Mastering GRASP: 9 Essential Object‑Oriented Design Patterns Explained
This article introduces the GRASP (General Responsibility Assignment Software Patterns) principles, outlines its nine core patterns—including Information Expert, Creator, High Cohesion, Low Coupling, Controller, Polymorphism, Pure Fabrication, Indirection, and Protected Variations—and explains how they guide responsibility assignment, object discovery, and design decisions to achieve high cohesion and low coupling in object‑oriented systems.
1. Overview
The core idea of GRASP is Responsibility Assignment. Craig Larman introduced GRASP in his book *Applying UML and Patterns*. Unlike GoF patterns, which solve specific problems, GRASP provides design principles that guide how to assign responsibilities to classes and define their relationships, forming the foundation for many design patterns.
1.1 GRASP Overview
GRASP consists of nine basic patterns:
Information Expert
Creator
High Cohesion
Low Coupling
Controller
Polymorphism
Pure Fabrication
Indirection
Protected Variations
1.2 Main Features
GRASP provides fundamental principles for assigning responsibilities, primarily used during analysis and modeling.
1.3 Core Idea
Assign each responsibility to the class that has the necessary information or behavior, ensuring high cohesion and clear responsibility boundaries.
2. Object‑Oriented Design
Object‑oriented design divides a system into relatively independent but interacting objects. Objects encapsulate attributes and behavior and communicate via messages.
Key steps include discovering objects, defining their attributes, defining their behavior (responsibilities), and establishing relationships.
2.1 Discovering Objects
Objects can be identified by extracting nouns from use cases. For example, in a student exam management system, nouns such as Administrator, SubjectItem, SubjectLibrary, Student, and Score become candidate objects.
2.2 Defining Object Behavior
Behaviors are identified by extracting verbs from use cases, such as creating a question bank, generating exams, and storing scores.
2.3 Object Relationships
Objects are linked through associations, aggregations, or other collaborations. Complex interactions can be managed using patterns like Indirection.
3. Information Expert Pattern
The Information Expert pattern assigns a responsibility to the class that possesses the required information, reducing unnecessary coupling and keeping data and behavior together.
3.1 Problem
How to decide which object should own a given responsibility?
3.2 Solution
Give the responsibility to the class that has the necessary information.
3.3 Benefits
Encapsulates information, clarifies responsibilities, and improves understandability.
3.4 Example
In the exam system, the SubjectItem class checks equality of question IDs, while the SubjectLibrary class handles adding questions to the library.
4. Creator Pattern
The Creator pattern assigns object‑creation responsibility to a class that contains, aggregates, records, frequently uses, or has the initialization data for the object.
4.1 Problem
Which class should be responsible for creating instances of another class?
4.2 Solution
If any of the following conditions hold, class B should create instances of class A: B contains A, B aggregates A, B records A, B frequently uses A, or B has the initialization data for A.
4.3 Benefits
Clear structure, promotes reuse, prevents scattered responsibilities, and reduces coupling.
4.4 Example
In a GUI, MainWindow creates Menu, ToolBar, and Dialog; Dialog creates TextBox and Button. Placing creation in unrelated classes would increase coupling.
5. High Cohesion Pattern
High Cohesion groups closely related responsibilities within the same class, keeping the class focused and easy to understand.
5.1 Problem
How to reduce class complexity and simplify control?
5.2 Solution
Assign tightly related functions to the same class.
5.3 Benefits
Clear structure, single responsibility, easier maintenance, and reduced complexity.
6. Low Coupling Pattern
Low Coupling minimizes inter‑class dependencies when assigning responsibilities, making the system more adaptable to change.
6.1 Problem
How to lower the degree of association between classes?
6.2 Solution
Design responsibilities to reduce direct links between classes.
6.3 Benefits
Improved reusability, easier adaptation to change, and lower impact of modifications.
7. Controller Pattern
The Controller pattern assigns event‑handling responsibilities to a dedicated controller class, centralizing system‑level logic.
7.1 Problem
Which class should handle system events outside the UI layer?
7.2 Solution
Use a Controller (or Facade) class to process events.
7.3 Benefits
Prevents scattered responsibilities, supports high cohesion and low coupling, and eases future changes.
8. Polymorphism Pattern
Polymorphism uses polymorphic operations to assign type‑dependent behavior to the classes where the behavior occurs.
8.1 Problem
Who should own the definition of behavior that varies by type?
8.2 Solution
Define the behavior in each subclass that implements a common interface, leveraging polymorphism.
8.3 Benefits
Avoids duplicated code and conditionals, and simplifies extension of new types.
9. Pure Fabrication Pattern
Pure Fabrication introduces artificial classes to hold responsibilities that do not naturally belong to domain classes, preserving high cohesion and low coupling.
9.1 Problem
Where to place responsibilities that do not fit any domain class?
9.2 Solution
Create a non‑domain class to own those responsibilities.
9.3 Benefits
Higher cohesion, lower coupling, and better reusability.
10. Indirection Pattern
Indirection inserts an intermediate class to mediate complex interactions between other classes, reducing direct coupling.
10.1 Problem
How to avoid direct associations between multiple classes?
10.2 Solution
Assign the association responsibility to a third‑party class.
10.3 Benefits
Higher cohesion, lower coupling, and increased reuse.
11. Protected Variations Pattern
Protected Variations encapsulates points of likely change behind stable interfaces to protect the rest of the system.
11.1 Problem
How to shield the system from unstable or varying elements?
11.2 Solution
Define stable interfaces around volatile parts; clients depend only on the interface.
11.3 Benefits
Improved adaptability, high cohesion, and reduced coupling.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
ITFLY8 Architecture Home
ITFLY8 Architecture Home - focused on architecture knowledge sharing and exchange, covering project management and product design. Includes large-scale distributed website architecture (high performance, high availability, caching, message queues...), design patterns, architecture patterns, big data, project management (SCRUM, PMP, Prince2), product design, and more.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
