Decorator Intent Also known as Wrapper Example: a Text Window Add additional responsibilities and functionality to objects dynamically Also known as Wrapper Example: a Text Window
Decorator: Motivation & Application Subclassing can only add functionality at runtime Avoid enumerating all possible sub classes Such as adding a border function to text window. Use with optional functionality
Decorator: Structure Participants: Component, ConcreteComponent, Decorator, ConcreteDecorator
Decorator: Consequences Positives More flexibility than static inheritance Avoids feature laden classes high in hierarchy Negatives Lots of little objects Interface conformance
Flyweight Intent: Use sharing to support large numbers of fine-grained objects efficiently Origin: A boxing class which includes fighters weighing less than 112 lb (50 kg) but above 108 lb. Example: Character in a word processor
Flyweight: Motivation & Application Applications that could benefit from using objects But the objects are very small and numerous
Flyweight: Structure Participants: Flyweight, ConcreteFlyweight, UnsharedConcreteFlyweight, FlyweightFactory, Client
Flyweight: Consequences Positives Space saving by using shared objects Adds functionality to the application Negatives Adding processing time of computing extrinsic state Time can be reduced
Any Questions?