CloudCoders / Design-Patterns

Project for learning and discuss about design patterns
16 stars 1 forks source link

Redesign of decorator pattern #12

Open srgtrujillo opened 7 years ago

srgtrujillo commented 7 years ago

I've opened this pull request to discuss the necessary changes so that the implemented example complies with the principles of the Decorator Pattern

1

Cotel commented 7 years ago

I've made some refactors and now IngredientDecorator makes use of by correctly (though it is not the most clever way to implement this example (Noodles could be an abstract class too and every noodles and ingredient only should need to define its cost reducing that way lines of code)).

I've detected a bug too. When showPrice() is called the price is shown correctly while noodles are not decorated or when they are decorated only by ingredients. But when the type changes to a sauce decorator it only returns the base price again because it has no calculateTotalCost() from ingredients decorators.

Does this mean we are not implementing the pattern correctly yet? If an object gets decorated it shouldn't lose its previous decorators isn't it?

tonilopezmr commented 7 years ago

@srgtrujillo You still alive?