WEEK FIVE - Decorator Pattern
It’s important to know why you're using it and to learn how to communicate about it with other developers.
It’s important to know why you're using it and to learn how to communicate about it with other developers.
The main reason to use the Decorator pattern—also known as the Wrapper pattern—is a need to add functionality to a class without modifying its code or disturbing its inheritance. While you may want the class to have more functionality, using the Decorator pattern means that your improved functionality version doesn’t have to reuse the existing functionality by extending the class.
Here's an example. Given an interface named Action with two methods, act1() and act2(), and a concrete version of this interface named ConcreteAction, the Decorator would be a class that implements Action and whose constructor takes an Action (usually ConcreteAction).
No comments:
Post a Comment