#include <iostream>
#include <bits/stdc++.h>
class RestaurantEmployee {
public:
virtual void washDishes() {
std::cout << "Washing dishes...\n";
}
virtual void serveFood() {
std::cout << "Serving food...\n";
}
virtual void cookFood() {
std::cout << "Cooking food...\n";
}
virtual ~RestaurantEmployee() = default;
};
// Dishwasher overrides unnecessary methods
class Dishwasher : public RestaurantEmployee {
public:
void washDishes() override {
std::cout << "Dishwasher: Washing dishes...\n";
}
void serveFood() override {} // Not needed, but must be implemented
void cookFood() override {} // Not needed, but must be implemented
};
// Waiter overrides unnecessary methods
class Waiter : public RestaurantEmployee {
public:
void serveFood() override {
std::cout << "Waiter: Serving food...\n";
}
void washDishes() override {} // Not needed, but must be implemented
void cookFood() override {} // Not needed, but must be implemented
};
// Chef overrides unnecessary methods
class Chef : public RestaurantEmployee {
public:
void cookFood() override {
std::cout << "Chef: Cooking food...\n";
}
void washDishes() override {} // Not needed, but must be implemented
void serveFood() override {} // Not needed, but must be implemented
};
//above is not following interface segregation principles because wash dishes anf cook food is meaning less
//for waiter so we don't need to implement them
//Now lets make it follow the ISP
// Separate interfaces for specific tasks
class Dishwashing {
public:
virtual void washDishes() const = 0;
virtual ~Dishwashing() = default;
};
class FoodServing {
public:
virtual void serveFood() const = 0;
virtual ~FoodServing() = default;
};
class Cooking {
public:
virtual void cookFood() const = 0;
virtual ~Cooking() = default;
};
// Dishwasher implements only Dishwashing
class Dishwasher : public Dishwashing {
public:
void washDishes() const override {
std::cout << "Dishwasher: Washing dishes...\n";
}
};
// Waiter implements only FoodServing
class Waiter : public FoodServing {
public:
void serveFood() const override {
std::cout << "Waiter: Serving food...\n";
}
};
// Chef implements only Cooking
class Chef : public Cooking {
public:
void cookFood() const override {
std::cout << "Chef: Cooking food...\n";
}
};