I have background C and am new to C ++. I have a basic design question. I have a class (I will call it a “chef” b / c a problem with which I seem to be very similar to it, both in terms of complexity and problems), which basically works like this
class chef { public: void prep(); void cook(); void plate(); private: char name; char dish_responsible_for; int shift_working; etc... }
in pseudocode, this is implemented line by line:
int main{ chef my_chef; kitchen_class kitchen; for (day=0; day < 365; day++) { kitchen.opens(); .... my_chef.prep(); my_chef.cook(); my_chef.plate(); .... kitchen.closes(); } }
The chef class seems to be a monster class and has the potential to become one of them. the chef also seems to violate the principle of shared responsibility, so instead we should have something like:
class employee { protected: char name; int shift_working; } class kitchen_worker : employee { protected: dish_responsible_for; } class cook_food : kitchen_worker { public: void cook(); etc... } class prep_food : kitchen_worker { public: void prep(); etc... }
and
class plater : kitchen_worker { public: void plate(); }
etc.
I admittedly still struggle with how to implement it at runtime, so that if, for example, a plater (or "a chef in his capacity as a plater") decides to return home halfway through dinner, then the chef a new shift should work.
This seems to be related to the broader question that I have: if the same person always does the cooking, cooking and coating in this example, what is the real practical advantage of having this class hierarchy simulate what does one chef do? I suppose this attacks the “fear of adding classes,” but at the same time, right now or in the foreseeable future, I don’t think supporting the chef class in its entirety is terribly cumbersome. I also believe that in the most understandable sense for a naive code reader, you can see three different methods in the chef's object and move on.
I understand that this can threaten to become cumbersome when / if we add methods such as "cut_onions ()", "cut_carrots ()", etc., possibly each with their own data, but it seems to be with them can be done by making the prep () function, say, more modular. Moreover, it seems that the SRP, taken to its logical conclusion, will create the class "onion_cutters" "carrot_cutters", etc .... and it’s still hard for me to see the value of this, given that somehow the program has to make sure that the same worker cuts onions and carrots, which helps to maintain a state variable in the same way in different methods (for example, if a worker cuts onion slices of his fingers, he no longer has the right to cut carrots), while in the monster chef class it seems that all that cares.
Of course, I understand that then it becomes less about the existence of a meaningful "object-oriented design", but it seems to me that if we need to have separate objects for each of the chef's tasks (which seems unnatural, given that the same person performs all three functions), this, apparently, prioritizes software development over the conceptual model. I feel that object oriented design is useful here if we want to have, say, "meat_chef" "sous_chef" "three_star_chef", which are probably different people. Moreover, the problem associated with the run-time problem is that there are apparently complex overhead costs, with strict application of the principle of single responsibility, which must be changed, and the basic data that make up the employee of the base class will be changed and that it change is reflected in subsequent steps of time.
Therefore, I am tempted to leave it more or less as it is. If someone can clarify why this would be a bad idea (and if you have any suggestions on how best to continue), I would be most obliged.