Return to site

Decorator design pattern c examples

broken image
broken image

Our application will be flexible enough to take on new functionality to meet changing requirements. This yields another benefit: flexible design. this is not a design time implementation. All this happens dynamically at runtime, i.e. Instead, you modify the object using a wrapper decorator class.

broken image

The pattern supports the Open/Closed principle of SOLID software design: you don’t change the implementation of an existing object. The result is a bloated class structure and a hard-to-maintain application. Class-explosion means that you create a large number of concrete classes from a base class to allow for the combination of different possible behaviour types. It is an alternative solution to subclassing: you can always create subclasses to an object to extend and modify its functionality but that can result in class-explosion. The result is an enhanced implementation of the object which does not break any client code that’s using the object. It achieves this goal by wrapping the object in a decorator class leaving the original object intact. The Decorator pattern aims to extend the functionality of objects at runtime.

broken image