Using the decorator pattern

Another approach to implementing cross-cutting concerns is to use the decorator pattern. The decorator pattern can add behaviors dynamically to an object, including behaviors for cross-cutting concerns. It is essentially like creating a wrapper to handle a cross-cutting concern around some other object. The following diagram shows the decorator pattern:

In the preceding diagram, the ConcreteComponent class implements the IComponent interface and is a class that can either be used on its own or wrapped in one or more decorators. The Decorator class is an abstract class that also implements the IComponent interface ...

Get Software Architect's Handbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.