-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Discuss about Decorator pattern in Little Kai example #1
Comments
Updated |
Can Decorators be implemented through kotlin's extension functions too? The Decorator would define a new function for the decorated class. In our case, IngredientDecorator would define |
You could do an example |
I've been trying and I don't think it is possible. 1st reason is extension functions scope is really strange. If I declare an extension function for Noodles inside IngredientDecorator it will never be reached from nowhere. 2nd reason. In my example i have removed abstract class IngredientDecorator(protected val noodles: Noodles) : Noodles {
override abstract protected val cost : Double
fun Noodles.calculateCost() : Double = noodles.cost + cost // Both of this costs are referencing Noodles.costs
} The problem is, when you declare an extension function, 3rd problem is that if we do |
Ok, I've been reading Decorator's entry in Wikipedia and we are doing this pattern badly. As @srgtrujillo said, the Decorator pattern Adds behaviour to an object and gives the possibility to remove it too. It adds responsabilities to an object dynamically and in a transparent way. It can be used when extension via inheritance is not possible or when there is no good reason to use it. So, what do you want to do? It is better to make another example? We keep this one even with that new implementation? It was a good idea but we are losing the point with the new changes. Keeping We can think of another example for decorators within Little Kai example. |
I said that in class that isn't a good example |
What do you think? What would you change?
The text was updated successfully, but these errors were encountered: