Should Decorators Preserve the Component Interface?

09/14/2020
by   Virginia Niculescu, et al.
0

Decorator design pattern is a well known pattern that allows dynamical attachment of additional functionality to an object. Decorators have been proposed as flexible alternative to subclassing for extending functionality. Still, the Decorator pattern has certain limitations, especially related to the fact that in its classical form it is constrained to a single interface, which is implicitly defined by the type of the concrete components that we intend to decorate. Another problem associated to the Decorator pattern is related to the linear composition of the decorations, which could lead to problems in accessing the newly added responsibilities. In this context, the paper presents variants of the Decorator pattern: MixDecorator and D2Decorator, and a variant specific only to C++ language based on templates - HybridDecorator. MixDecorator could be considered a new enhanced version of the Decorator pattern that eliminates some constraints of the Decorator pattern, but also it could be used as a base of a general extension mechanism. The main advantage of using MixDecorator is that it allows direct access to all newly added responsibilities, and so, we may combine different interface-responsibilities (newly added public methods) and operate with them directly and in any order, hiding the linear composition of the decorations. D2Decorator is a variant based on a double-dispatch mechanism. The C++ metaprogramming mechanism based on templates allows an interesting hybrid variant of the Decorator - HybridDecorator, which mixes on-demand defined inheritance with composition. Using these variants of the Decorator pattern we are not longer limited to one single interface; the set of the messages that could be sent to an object could be enlarged, and so, we may consider that using them, we can dynamically change the type of objects.

READ FULL TEXT

page 8

page 13

page 15

page 21

research
10/23/2018

Nonequispaced Fast Fourier Transform (NFFT) Interface for Julia

This report describes the newly added Julia interface to the NFFT3 libra...
research
09/10/2019

Extending the Service Composition Formalism with Relational Parameters

Web Service Composition deals with the (re)use of Web Services to provid...
research
02/06/2018

Code Reuse With Transformation Objects

We present an approach for a lightweight datatype-generic programming in...
research
09/11/2017

Verification of Asynchronous Systems with an Unspecified Component

Component-based systems evolve as a new component is added or an existin...
research
04/11/2019

Prolific Compositions

Under what circumstances might every extension of a combinatorial struct...
research
10/28/2016

Flexible constrained sampling with guarantees for pattern mining

Pattern sampling has been proposed as a potential solution to the infamo...
research
01/10/2018

To Pool or Not To Pool? Revisiting an Old Pattern

We revisit the well-known object-pool design pattern in Java. In the las...

Please sign up or login with your details

Forgot password? Click here to reset