I would like to implement the Decorator design pattern using inheritance ( Decorator extends Component), because I need access to the protected fields / methods of the Component class.
The problem is that the Component class is an algorithm; it performs some preliminary processing during construction and contains a significant amount of data. Now every time I decorate a component, I will create a new instance of Decorator, which will require the creation of a new (useless) instance of Component, which performs unnecessary calculations and stores unnecessary data.
I wanted to use interfaces instead of inheritance, but then I could not get access to the information protected by the component.
Can you worry about wasting resources when extending the Component class? And if so, how can I avoid this without losing access to the information I need?
Finally, I can create an instance of Decorator supplying it with “dummy” data so that it does the minimum amount of computation, but this solution seems messy.
Thank.
yurib source
share