| GRASP Patterns | |
| GRASP stands for General
Responsibility Assignment Software Patterns. The author, Craig Larman, is a great teacher and scholar. This table is from his book. |
|
| Pattern | Description |
|---|---|
|
Expert |
Who, in the general case is responsible? Assign a responsibility to the information expert -- the class that has the information necessary to fulfill the responsibility. |
|
Creator |
Who creates? Assign class B the responsibility to create an instance of class A if one of the following is true:
|
|
Controller |
Who handles a system event? Assign the responsibility for handling a system event message to a class representing one of these choices:
|
|
Low Coupling |
How to support low dependency and increased reuse? Assign responsibilities so that coupling remains low. |
|
High Cohesion |
How to keep complexity manageable? Assign responsibilities so that cohesion remains high. |
|
Polymorphism |
Who, when behavior varies by type? When related alternatives or behaviors vary by type (class), assign responsibility for the behavior—using polymorphic operations—to the types for which the behavior varies. |
|
Pure Fabrication |
Who, when you are desperate, and do not want to violate High Cohesion and Low Coupling? Assign a highly cohesive set of responsibilities to an artificial class that does not represent anything in the problem domain, in order to support high cohesion, low coupling, and reuse. |
|
Indirection |
Who, to avoid direct coupling? Assign the responsibility to an intermediate object to mediate between other components or services, so that they are not directly coupled. |
|
Don't Talk to Strangers |
Who, to avoid knowing about the structure of indirect objects? Assign the responsibility to a client's direct object to collaborate with an indirect object, so that the client does not need to know about the indirect object. Within a method, messages can only be sent to the following objects:
|