Gang of Four Patterns 23 total 15 useful How are they different from GRASP Patterns?
Adaptor Resolve incompatible interfaces i.e. use an existing interface that cannot be changed, a third party “Use a level of indirection to create a consistent interface.”
Fig Adaptor How is this different from Fig. 25.1?
Fig Using the adapter Compare to Fig
GRASP vs. GoF GRASP is at work in other patterns Look for underlying principles, such as “Façade Object”
Fig The Goals: Protection at a variation point Low Coupling
Fig Updated Domain Model
Factory Pattern Object Creation issues Who creates the adapter or interface? How do you know which adapter/interface to create? How to maintain High Cohesion? Who should be responsible for creating complex objects?
Factory is a Common Solution Pure Fabrication Hide complex creation logic Separate responsibilities into a cohesive helper Memory management Performance management
The Factory Pattern
Singleton Some class should only have one object instance at runtime Usual implementation is a static method Supports global visibility Supports single access point If instance == null …. If not null, then use the existing instance object.
Singleton Pattern
Implicit getInstance Singleton Msg
Fig Final design
Strategy Design for varying but related algorithms or policies Design to change/ swap them out. Make each a separate class, but with a common interface.
Fig. 26.9
Strategy in Collaboration Context object passes a reference to itself (this) to the Strategy Object.
Fig “pricingStrategy” association is a method invocation
Fig How is this different from Adapter? Factory decides which adapter to create.
Composite How to treat a group of objects the same as an atomic object Use the same interface Implement composite object to hold a list of atomic objects Best discount by: Time Customer type product
The Composite Pattern Outer Object Inner Objects
Collaboration with a Composite
Inheritance Relationships
Fig Store-defined discount, when sale is created
Fig Customer-type discount, when customer ID is entered.
Fig How customer-type discount is applied. An alternative to Fig Passes the customer object, rather than the customer ID. Why?
Facade Common unified interface Allows for easy customization Make a single point of contact to wrap the subsystem
Fig
Observer Publish – Subscribe Delegation Event Standard stuff, but from the OOD POV. Update the GUI window when the sale total changes.
Fig
Fig How are the various methods invoked?
Fig SSD explains how the various methods are invoked. Follow the data flows.
Fig
Fig
Fig How is this different from Fig ?
Fig Publish-Subscribe example: alarm clock.
Summary Why are patterns used? What is the designers goal? How do you follow the data flows? How many core patterns do you think there are?