I came across this example in Head First Design Patterns book. Pizza class has the following methods:
- prepare
- bake
- cut
- box
I believe these methods shouldn’t go into the Pizza class and they should go into a separate class. Even if we ignore the fact that Single Responsibility Principle is violated, I still think these should go into a separate class (say PizzaStore).
Please comment.
I actually think it’s ok if they are in the
Pizzaclass, as they can represent state changes, and are thus part of the class logic:bake()could be used to change the state of thePizzaobject. It could initially berawand after the method call it could bebaked. (haha, baked!).cut()could be used to modify the membernumberOfSlices. Initially it could be1, followed by2,4and so on.These methods are of course called from the outside, but they modify the state of the object. For me it makes sense that they are part of the class.