Senior
What is GRASP?
sobes.tech AI
Answer from AI
GRASP (General Responsibility Assignment Software Patterns) is a set of universal principles for assigning responsibilities to classes and objects in object-oriented design. They help create flexible, maintainable, and reusable systems. The main GRASP patterns include:
- Information Expert: An object that has the necessary information to perform a task should take responsibility for that task.
- Creator: A class that contains or aggregates instances of other classes, is closely related to them, or has the initialization data for their creation, should take responsibility for creating them.
- Controller: A class responsible for handling system events (e.g., user actions) should take responsibility for coordinating the work of other objects but not for performing the work itself.
- Pure Fabrication: An artificially created class that does not reflect the domain concept but is created to reduce coupling, improve cohesion, or enable reuse.
- Low Coupling: A design principle aimed at minimizing dependencies between classes.
- High Cohesion: A design principle aimed at ensuring that the methods of a class are closely related in functionality.
- Polymorphism: Assigning responsibility for behavior selection based on the object type (via virtual methods).
- Protected Variations: A design principle that protects against changes in other elements (objects, subsystems, systems) by defining a stable interface.
- Indirection: Assigning responsibility to an intermediary object to avoid direct coupling between two elements.
Applying GRASP helps avoid "thick" controllers and managers, improves code structure, and facilitates its evolution.