Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

How are decorator patterns used in design patterns?


Asked by Maximiliano Roy on Dec 02, 2021 FAQ



Design Patterns - Decorator Pattern. Decorator pattern allows a user to add new functionality to an existing object without altering its structure. This type of design pattern comes under structural pattern as this pattern acts as a wrapper to existing class.
Thereof,
The decorator design pattern (decorator pattern in short) is a design strategy revealed in 1994 to expand the functionality of classes in object-oriented computer software. According to the pattern, any object can be expanded by a desired behavior without influencing the functionalities of other objects of the same classes.
Moreover, The decorator design pattern allows us to dynamically add functionality and behavior to an object without affecting the behavior of other existing objects within the same class. We use inheritance to extend the behavior of the class. This takes place at compile-time, and all the instances of that class get the extended behavior.
Furthermore,
This type of design pattern comes under structural pattern as this pattern acts as a wrapper to existing class. This pattern creates a decorator class which wraps the original class and provides additional functionality keeping class methods signature intact.
In fact,
We use inheritance to extend the behavior of the class. This takes place at compile-time, and all the instances of that class get the extended behavior. Decorator patterns allow a user to add new functionality to an existing object without altering its structure. So, there is no change to the original class.