Presentation is loading. Please wait.

Presentation is loading. Please wait.

GRASP: More Patterns for Assigning Responsibilities Presented By Dr. Shazzad Hosain.

Similar presentations


Presentation on theme: "GRASP: More Patterns for Assigning Responsibilities Presented By Dr. Shazzad Hosain."— Presentation transcript:

1 GRASP: More Patterns for Assigning Responsibilities Presented By Dr. Shazzad Hosain

2 GRASP Patterns Previously we have explored Information Expert Creator High Cohesion Low Coupling and Controller The other four GRASP patterns are Polymorphism Indirection Pure Fabrication and Protected Variations

3 Polymorphism Example: Let’s say you like to sale NextGen POS system to different countries. You need to integrate different external third- party tax calculators such as TaxMasterAdapter GoodAsGoldTaxProAdapter etc. If (Country == “US”) Use TaxMasterAdapter Else if (Country == “UK”) Use GoodAsGoldTaxProAdapter Else if …. End If

4 Polymorphism

5 UML Notation

6 Polymorphism Context/Problem: How to handle alternatives based on type? How to create pluggable software components? Solution: If alternatives or behaviors vary by type (class), then assign responsibility for the behavior – using polymorphic operations – to the types for which the behavior varies. Corollary: Do not test for the type of an object and use conditional logic to perform varying alternatives based on type.

7 Pure Fabrication Example: Suppose we need to save Sale object in a relational DB. Information Expert or Expert says Sale should do it, because Sale knows its total. But it violates Low Coupling and High Cohesion because Sale will be coupled with JDBC etc. This class is a Pure Fabrication – a figment of the imagination

8 Benefits of Pure Fabrication Sale remains well-designed, with high cohesion and low coupling The PersistentStorage class is itself relatively cohesive, having the sole purpose of storing or inserting objects in a persistent storage medium The PersistentStorage class is very generic and reusable object This class is a Pure Fabrication – a figment of the imagination Domain Class ?

9 Pure Fabrication Context/Problem: What object should have the responsibility, when you do not want to violate High Cohesion and Low Coupling, or other goals, but solutions offered by Expert (for example) are not appropriate? Solution: Assign a highly cohesive set of responsibilities to an artificial or convenience class that does not represent a problem domain concept – something made up, to support high cohesion, low coupling, and reuse. Finally, a pure fabrication implies making something up, which we do when we’re desperate!

10 Indirection Example of Indirectoin PersistentStorage Class is also an indirection. Act as an intermediary between the Sale and the database.

11 Indirection Context/Problem: Where to assign responsibility, to avoid direct coupling between two (or more) things? How to decouple objects so that low coupling is supported and reuse remains high? Solution: Create an intermediate object to mediate between other components or services so that they are not directly coupled. The intermediary creates and indirection between the other components.

12 Protected Variations Context/Problem: How to design objects, subsystems and systems so that the variations or instability in these elements does not have an undesirable impact on other elements? Solution: Identify points of predicted variation or instability; assign responsibilities to create a stable interface around them. Example: Prior external tax calculator is also a protected variation example.

13 References Chapter 22 of “Applying UML and Patterns – An Introduction to Object-Oriented Analysis and Design and the Unified Process” – by Craig Larman


Download ppt "GRASP: More Patterns for Assigning Responsibilities Presented By Dr. Shazzad Hosain."

Similar presentations


Ads by Google