-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathREADME.txt
More file actions
12 lines (8 loc) · 985 Bytes
/
README.txt
File metadata and controls
12 lines (8 loc) · 985 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
A demonstration of the GOF Decorator design pattern. A discount is decorated depending on the discount type to be applied. The discount is decorated with the various applicable discounts at run time.
Intent: Attach additional responsibilities to an object dynamically. Decorators provide a flexible alternative to subclassing for extending functionality.
Benefits: More flexible than static inheritance. Avoids function-laden classes high up the hierarchy.
Limitations: A decorator and its components aren't identical. Lots of little objects.
Applicability:
- To add responsibilies to individual objects dynamically and transparantly, without afftecting other objects.
- For responsibilities that can be withdrawn.
- When extention by subclassing is impractical. Sometimes a large number of independent extentions are possible and would produce an explosion of subclasses to support every combination. Or a class definition may be hidden or otherwise unavailable for subclassing.