3 unit - Structural pattern
3 unit - Structural pattern
Definition:
Bridge
Bridge
Bridge
Bridge – Abstraction part
Bridge – Implementation part
Bridge – Pattern Structure
Composite
• A tree structure of simple and composite
objects.
• Allows to treat the different objects in similar
fashion.
Composite (Structural)
• Intent
– Treat individual objects and multiple, recursively-
composed objects uniformly
• Applicability
– Objects must be composed recursively,
– And there should be no distinction between individual and
composed elements,
– And objects in the structure can be treated uniformly
– Part-Whole hierarchy of objects.
– Constant handling of objects as groups or individuals
Composite (Cont'd)
• Known Uses
– ET++ VObjects
– InterViews Glyphs, Styles
© E. Gamma, R. Helm, R. Johnson, J. Vlissides and Addison-Wesley
Leaf Composite
+operation() +operation()
+add(in c : Composite)
1
+remove(in c : Composite)
+getChild(in i : int)
{ forall g in children
g.operation(); }
Composite
Composite
Composite
Composite
Composite - Example
Composite (Cont'd)
• Consequences
+ Uniformity: treat components the same regardless of
complexity
+ Extensibility: new Component subclasses work wherever
old ones do
– Overhead: might need prohibitive numbers of objects
• Implementation
– Do Components know their parents?
– Uniform interface for both leaves and composites?
– Don't allocate storage for children in Component base
class
– Responsibility for deleting children
Decorator (Structural)
• Intent
– Adding objects with new responsibilities
– Add responsibilities to objects dynamically
© E. Gamma, R. Helm, R. Johnson, J. Vlissides and Addison-Wesley
• Applicability
– When extension by subclassing is impractical
– For responsibilities that can be withdrawn
• Definition
Decorator Diagram
• Structure
Component (Glyph) 1
© E. Gamma, R. Helm, R. Johnson, J. Vlissides and Addison-Wesley
+operation() -component
ConcreteDecoratorB
ConcreteDecoratorA { super.operation();
-addedState addedBehavior(); }
+operation()
+operation()
+addedBehavior()
Decorator - Diagram
Decorator
Decorator Overview
• A Decorator, also known as a Wrapper, is an object that has an interface
identical to an object that it contains. Any calls that the decorator gets, it
relays to the object that it contains, and adds its own functionality along
the way, either before or after the call.
– Interface occlusion
– Identity crisis
• Implementation
– Interface conformance
– Use a lightweight, abstract base class for Decorator
– Heavyweight base classes make Strategy more attractive
Decorator (Cont'd)
• Known Uses
– Embellishment objects from most OO-GUI toolkits
– ParcPlace PassivityWrapper
© E. Gamma, R. Helm, R. Johnson, J. Vlissides and Addison-Wesley
– InterViews DebuggingGlyph
Facade
• A single class that represents an entire
subsystem
Definition
Facade
Facade
© E. Gamma, R. Helm, R. Johnson, J. Vlissides and Addison-Wesley
Façade
Façade
Façade
Façade
Façade
Façade
Façade - Example
Facade Overview
• Example: WYSIWYG Editor (Cont'd)
– Spelling checking & hyphenation
• Iterator
• Visitor
• Some more patterns
– Template Method
– Singleton
– Façade
• Observations and Conclusions
• Further reading
Flyweight pattern
• A fine-grained instance used for efficient
sharing
• Where we need to create many objects and all
these objects share some kind of common
data.
Flyweight pattern
Flyweight pattern
Flyweight pattern
Flyweight pattern
Proxy
• An object representing another object.
• A well-known example of the proxy pattern is
a reference counting pointer object.
Definition
Proxy