Presentation on More Patterns for Assigning Responsibilities for
Presentation on More Patterns for Assigning Responsibilities for GRASP Submitted by WWW. ASSIGNMENTPOINT. COM www. assignmentpoint. com
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 www. assignmentpoint. com
Polymorphism Example: Let’s say you like to sale Next. Gen POS system to different countries. You need to integrate different external third-party tax calculators such as Tax. Master. Adapter Good. As. Gold. Tax. Pro. Adapter etc. If (Country == “US”) Use Tax. Master. Adapter Else if (Country == “UK”) Use Good. As. Gold. Tax. Pro. Adapter Else if …. …. End If www. assignmentpoint. com
Polymorphism www. assignmentpoint. com
UML Notation www. assignmentpoint. com
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. www. assignmentpoint. com
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 www. assignmentpoint. com
Benefits of Pure Fabrication Sale remains well-designed, with high cohesion and low coupling The Persistent. Storage class is itself relatively cohesive, having the sole purpose of storing or inserting objects in a persistent storage medium The Persistent. Storage class is very generic and reusable object Domain Class ? This class is a Pure Fabrication – a figment of the imagination www. assignmentpoint. com
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! www. assignmentpoint. com
Indirection Example of Indirectoin Persistent. Storage Class is also an indirection. Act as an intermediary www. assignmentpoint. com between the Sale and the database.
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. www. assignmentpoint. com
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. www. assignmentpoint. com
- Slides: 12