GRASP software patterns

This is a UML diagram (created in IBM Rhapsody...

Image via Wikipedia

My final exam is on Tuesday and covers object-orientated design and programming – hence the Groovy Game of Life code.

Software patterns are a big part of the course and part of that is the simple task of remembering what each pattern does. I have found Head First Design Patterns useful but it covers few patterns and certainly not the basic GRASP ones, that I do have to know.

GRASP stands for General Responsibility Assignment Software Patterns (or Principles – I actually think this comes closer to expressing what this is all about anyway).

These are:

Information Expert, solving the problem of the general principle of assigning responsibilities to objects by assigning the responsibilities to the information expert – the class that has the information necessary to fulfil the responsibility.

Creator, solving the problem of what should be responsible for creating a new instance of some class by assigning the responsibility of creating a new instance of class A  to the class, B, that:

  • aggregates A objects; or
  • contains A objects; or
  • records instances of A objects; or
  • closely uses A objects; or
  • has the initialising data that will be passed to A when it is created.

(If more than one class displays these characteristics then aggregation or composition should be preferred.)

Low Coupling, solving the problem of creating classes that have low levels of dependency and face a low impact when other classes are changed and can be more easily reused by assigning responsibilities so that coupling remains low.

Controller, which addresses the question of what should be responsible for handling an input system event by assigning the responsibility to a class that represents one of the following choices:

  • It represents the overall system, device or subsystem (it is a facade controller); or
  • It represents a use case scenario within which the system event occurs, often named Handler or Coordinator, etc (it is a use-case or session controller).

High Cohesion, which addresses the problem of how to keep complexity manageable and how to keep objects focused by assigning responsibilities so that cohesion remains high.

2 thoughts on “GRASP software patterns

  1. Pingback: Creational patterns | cartesian product

  2. Pingback: Behavioural software patterns | cartesian product

Comments are closed.