Skip to main content
9 events
when toggle format what by license comment
Jan 19, 2020 at 14:27 history closed candied_orange
BobDalgleish
Greg Burghardt
8bittree
gnat
Needs details or clarity
Jan 14, 2020 at 16:09 comment added Filip Milovanović P.S. If it's still unclear, do a simple exercise; create a class that implements some interface (with a couple of methods - try to come up with something meaningful, but simple). Then write some code that calls those methods through the interface (through a variable of the interface type). Now create two decorators, but do it your way, without having a base class for them - wrap them over your example component without changing the code that actually calls the interface methods from before. It can be done, but you'll encounter some repetition.
Jan 14, 2020 at 16:03 comment added Filip Milovanović Other than that, it's just a wrapper over any other component that implements that same interface. The reason that there's an abstract Decorator base class is that all decorators need to store the wrapped component somewhere, so they share that bit of their implementation. 2/2
Jan 14, 2020 at 16:03 comment added Filip Milovanović With decorator, you are not going to have some generic "decorate()" method; you are going to have components that do something, and share a certain set of public methods and properties (an abstract interface). The key idea of decorators is that they add optional functionality in a transparent way - i.e., code that calls it doesn't even know there's a decorator in between (or several of them). To achieve that, a decorator must have the same abstract interface. That's crucial. 1/2
Jan 14, 2020 at 15:14 answer added Christophe timeline score: 4
Jan 14, 2020 at 14:26 history edited Christophe CC BY-SA 4.0
added 267 characters in body
Jan 14, 2020 at 14:00 review Close votes
Jan 19, 2020 at 14:30
Jan 14, 2020 at 13:22 comment added gnat see Should a question that is meaningless without viewing an external link be closed?
Jan 14, 2020 at 13:21 history asked ha9u63a7 CC BY-SA 4.0