Author:
Virginia Niculescu
Affiliation:
Faculty of Mathematics and Computer Science, Babeş-Bolyai University, 1 M. Kogalniceanu, Cluj-Napoca, Romania
Keyword(s):
Decorator, Patterns, Templates, Policy, Accessibility, Extensibility, Interfaces, C++.
Abstract:
C++ Policies represent an interesting metaprogramming mechanism that allows behavior infusion in a class. In this paper, we will investigate the possibility of using them for the implementation of some extended Decorator pattern variants. For the MixDecorator variant, policies are used to simulate extension methods, which are needed for implementation. Beside this, other two alternatives for Decorator pattern are proposed: one purely based on inheritance, and another that is a hybrid one; the last one wraps an object with decorations defined as a linear hierarchy of classes – introduced using policies. This is possible since a policy introduces a kind of recursive definition for inheritance. The advantages and disadvantages of these variants are analyzed on concrete examples. The hybrid variant presents many important advantages that qualify it as a valid and efficient Decorator pattern variant – HybridDecorator.