About

GRASP and Core Heuristics

GRASP and Core Heuristics

GRASP (General Responsibility Assignment Software Patterns) guides how to assign responsibilities to classes during object design.

Core GRASP Patterns

  1. Information Expert: Assign responsibility to the class that possesses the necessary information to fulfill it.
  2. Creator: Assign creation of object B to class A if A aggregates, contains, or records B.
  3. Controller: Non-UI class coordinating system operations and workflow events.
  4. Low Coupling: Organize responsibilities to keep inter-class dependencies minimal.
  5. High Cohesion: Ensure the responsibilities of each class are focused and closely related.
  6. Polymorphism: Assign varying behavior to polymorphic classes rather than conditional statements.
  7. Pure Fabrication: Create an artificial domain class (e.g., DatabaseService, Logger) purely to achieve high cohesion and low coupling.
  8. Protected Variations: Shield points of anticipated change with stable interfaces.

Pragmatic Design Heuristics

Exercise 1

According to the Information Expert pattern, which class should calculate total order price: the Order class or the Customer class?

Show solution ↓
Solution

The Order class, because it holds direct access to the collection of OrderItem objects with their respective quantities and prices.