GRASP Patterns: Assigning Responsibilities to Objects
GRASP Patterns
GRASP stands for General Responsibility Assignment Software Patterns. It guides in assigning responsibilities to collaborating objects. The 9 GRASP patterns are:
- Creator
- Information Expert
- Low Coupling
- Controller
- High Cohesion
- Indirection
- Polymorphism
- Protected Variations
- Pure Fabrication
Responsibility
Responsibility is accomplished by a single object or a group of objects collaboratively. GRASP helps in deciding which responsibility should be assigned to which object or class. It involves identifying objects and responsibilities from the problem domain and how objects interact with each other. A blueprint for those objects is defined, i.e. a class with methods implementing those responsibilities.
Creator
Decides who creates an object based on the objects’ association and interaction. A ‘container’ object creates ‘contained’ objects.
Expert
Assigns responsibilities to an object based on the information it has to fulfill that responsibility.
Low Coupling
Minimizes dependency between objects to make the system maintainable, efficient, and code reusable.
Controller
Delegates requests from the UI layer objects to domain layer objects and coordinates the overall activity.
High Cohesion
Related responsibilities are grouped into one manageable unit to make the element easily understandable, maintainable, and promote code reuse.
Polymorphism
Guides in deciding which object is responsible for handling varying elements based on element type.
Pure Fabrication
Assigns a set of related responsibilities that don’t represent any domain object, providing a highly cohesive set of activities.
Indirection
Introduces an intermediate unit to communicate between other units to avoid direct coupling.
Protected Variation
Provides a well-defined interface to avoid the impact of variations of some elements on other elements, promoting flexibility and protection from variations.
