Conversation
| assertThat(Tuna(Pork(UdonNoodles())).calculateCost(), `is`(10.75)) | ||
|
|
||
| @Test | ||
| fun `has the same interface`() { |
|
I've made some refactors and now IngredientDecorator makes use of I've detected a bug too. When 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? |
| fun calculateCost() : Double | ||
| interface Noodles { | ||
| fun calculateCost(): Double | ||
| fun calculateTotalCost(): Double |
There was a problem hiding this comment.
Then IngredientDecorator is not adding any behaviour 😵
There was a problem hiding this comment.
I think with the fact of implementing the decorator function in each concrete case, it's already adding behaviour. What do you think about it?
There was a problem hiding this comment.
But If Noodles already has a method calculateTotalCost() then, every child that implements it modifies its behaviour. Noodles shouldn't have that method, it belongs to IngredientDecorator and the concrete decorators which will add that behaviour to Noodles.
|
|
||
| class Chicken(noodles: Noodles) : IngredientDecorator(noodles) { | ||
| override val COST: Double = 3.50 | ||
| class Chicken(noodles: Noodles, val COST: Double = 3.50): IngredientDecorator(noodles) { |
There was a problem hiding this comment.
COST is a constant. It shouln't go in the constructor because you are opening it to change and we are not interested in that.
There was a problem hiding this comment.
I think the keyword val make the constant COST inmutable.
There was a problem hiding this comment.
But you are placing the declaration in the constructor. You are giving the opportunity to set another COST when making a new instance.
There was a problem hiding this comment.
I've done some tests and you're right. I have extracted the COST variable from the constructor to an immutable constant.
|
@srgtrujillo You still alive? |

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