Decorator design pattern
The decorator design pattern is one of the structural patterns that allows us to extend the functionality of a class without modifying the class. This is achieved by creating a separate class and wrapping the main class with this new class, which allows us to add new functionality. This pattern allows us to make sure we are able to follow the single responsibility principle with our classes. Our classes can continue to focus on their primary responsibility, and any new functionality that needs to be added can be added using a decorator that would be triggered when the class is initialized. Because the logic of the decorator class gets executed at the time of creation of the object, the decorator pattern allows us ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access