Presentation is loading. Please wait.

Presentation is loading. Please wait.

Gang of Four Patterns 23 total 15 useful How are they different from GRASP Patterns?

Similar presentations


Presentation on theme: "Gang of Four Patterns 23 total 15 useful How are they different from GRASP Patterns?"— Presentation transcript:

1 Gang of Four Patterns 23 total 15 useful How are they different from GRASP Patterns?

2 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.”

3 Fig. 26.1 Adaptor How is this different from Fig. 25.1?

4 Fig. 26.2 Using the adapter Compare to Fig. 25.10

5 GRASP vs. GoF GRASP is at work in other patterns Look for underlying principles, such as “Façade Object”

6 Fig. 26.3 The Goals: Protection at a variation point Low Coupling

7 Fig. 26.4 Updated Domain Model

8 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?

9 Factory is a Common Solution Pure Fabrication Hide complex creation logic Separate responsibilities into a cohesive helper Memory management Performance management

10 The Factory Pattern

11 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.

12 Singleton Pattern

13 Implicit getInstance Singleton Msg

14 Fig. 26.8 Final design

15 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.

16 Fig. 26.9

17 Strategy in Collaboration Context object passes a reference to itself (this) to the Strategy Object.

18 Fig. 26.11 “pricingStrategy” association is a method invocation

19 Fig. 26.13 How is this different from Adapter? Factory decides which adapter to create.

20 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

21 The Composite Pattern Outer Object Inner Objects

22 Collaboration with a Composite

23 Inheritance Relationships

24 Fig. 26.17 Store-defined discount, when sale is created

25 Fig. 26.18 Customer-type discount, when customer ID is entered.

26 Fig. 26.19 How customer-type discount is applied. An alternative to Fig. 26.17. Passes the customer object, rather than the customer ID. Why?

27 Facade Common unified interface Allows for easy customization Make a single point of contact to wrap the subsystem

28 Fig. 26.20

29 Observer Publish – Subscribe Delegation Event Standard stuff, but from the OOD POV. Update the GUI window when the sale total changes.

30 Fig. 26.21

31 Fig. 26.22 How are the various methods invoked?

32 Fig. 26.23 SSD explains how the various methods are invoked. Follow the data flows.

33 Fig. 26.24

34 Fig. 26.25

35 Fig. 26.26 How is this different from Fig. 26.22?

36 Fig. 26.27 Publish-Subscribe example: alarm clock.

37 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?


Download ppt "Gang of Four Patterns 23 total 15 useful How are they different from GRASP Patterns?"

Similar presentations


Ads by Google