The GRASP Design Patterns
General Responsibility Assignment Software Patterns
We want to be able to reuse as many things as possible.
Heuristic – Allowing a person to discover or learn something for themselves
Responsibility-Driven Design (RRD)
Do object design by asking:
What are the responsibilities of the object?
Who does it collaborate with?
Can use a CRC diagram with this:
Responsibilities are an abstraction
Objects need to be assigned with responsibilities
Are implemented with methods in objects
Responsibility for persistence is a large-grained responsibility eg. User
Fine-grained responsibility, eg. Involving data
Patterns provide a vocabulary of design such as: state, straegy, façade
The GRASP Patterns
Very fundamental, basic principles of object design.
Protected Variations Information Expert
Most general, basic principle.
Something that knows a lot about certain things.
Assign a responsibility to the object that has the information necessary.
Eg. Assign responsibility to employee
Have many experts. Don’t want one complex information expert (Anti-
Pattern, ‘God object’).
A god object lacks cohesion and has too many responsibilities.
An object that creates something (eg. A)
Choose an object that:
Contains or aggregates A
Closely uses A
Has the initialising data for A
Eg. Board is the creator of square
Static Model: Board Square
What object in the domain receives requests for work from the UI layer.
Choose a class whose name suggests the overall “system”, or represents the
use case scenario. Low Coupling – evaluative pattern
Things being linked together loosely.
Coupling describes the degree of togetherness, and is reflected by the
number of links.
We want to minimise dependencies.
To create reusable components that are resilient to change.
Making sense as a unit.
A measure of how strongly related and focused the responsibilities of a
Low cohesion do too many unrelated things (undesirable).
Low Cohesion – Bad High Cohesion – Good
:Monopoly Game :Monopoly Game :?? :??
Behaviour varies by type.
Not really a pattern.
Apply different behaviours to their appropriate type. Pure Fabrication
Grouping of related responsibilities.
Avoid direct coupling
Use mediating objects
Limit the effect of instability.