Design patterns in C# - Decorator
Role The role of the Decorator pattern is to provide a way of attaching new state and behavior to an object dynamically. The object does not know it is being "decorated," which makes this a useful pattern for evolving systems. A key implementation point in the Decorator pattern is that decorators both inherit the original class and contain an instantiation of it. Illustration As its name suggests, the Decorator pattern takes an existing object and adds to it. As an example, consider a photo that is displayed on a screen. There are many ways to add to the photo, such as putting a border around it or specifying tags related to the content. Such additions can be displayed on top of the photo. The beauty of this pattern is that: • The original object is unaware of any decorations. • There is no one big feature-laden class with all the options in it. • The decorations are independent of each other. • The decorations can be composed together in a mix-and-match