GRASP (Object Oriented Design)

From Wikipedia, the free encyclopedia

GRASP stands for General Responsibility Assignment Software Patterns (or sometimes Principles). It is used in object oriented design, and gives guidelines for assigning responsibility to classes and objects.

Examples of different patterns/principles used in GRASP are: Information Expert, Creator, Controller, Low Coupling, High Cohesion, Polymorphism, Pure Fabrication, Indirection, Protected Variations. All these patterns answer some software problem, and in almost every case these problems are common to most every software development project, thus they don't exist to facilitate new information but to better document and standardize old, tried-and-true programming principles in object oriented design.

"The critical design tool for software development is a mind well educated in design principles. It is not the UML or any other technology" (Larman, Craig. Applying UML and Patterns - Third Edition. [1]). Thus, GRASP is really just a toolset, a learning aid to help in the design of object oriented software.

Contents

[edit] Information Expert

This pattern represents the basic principle of responsibility assignment. It states that responsibility should be assigned to the information expert—the class that has all the necessary information.

[edit] Creator

The Creator pattern deals with assigning the responsibility of creating new objects (instances of classes). New instances of class Class should be created by a class such that:

  • it aggregates instances of Class, or;
  • it contains instances of Class, or;
  • it records instances of Class, or;
  • it closely uses instances of Class, or;
  • it has the necessary information for creating the new instance of Class.

[edit] Controller

The Controller pattern assigns the responsibility of dealing with system events to a non-UI class that represent the overall system or a use case scenario. A use case controller should be used to deal with all system events of a use case, and may be used for more than one use case (for instance, for use cases Create User and Delete User, one can have one UserController, instead of two separate use case controllers).

[edit] Low Coupling

Low Coupling is an evaluative pattern, which dictates how to assign responsibilities to support:

  • low dependency between classes;
  • low impact in a class of changes in other classes;
  • high reuse potential.

[edit] High Cohesion

High Cohesion is also an evaluative pattern, and helps manage complexity by assigning highly related (cohesive) responsibilities to a class. Like Low Coupling, High Cohesion also favors maintainabilty and reuse.

[edit] Polymorphism

According to the Polymorphism pattern, responsibility of defining the variation of behaviors based on type is assigned to the types for which this variation happens. This is achieved using polymorphic operations.

[edit] Pure Fabrication

A pure fabrication is a class that does not represent a concept in the problem domain, specially made up to achieve low coupling, high cohesion, and the reuse potential thereof derived (when a solution presented by the Information Expert pattern does not).

[edit] Indirection

The Indirection pattern supports low coupling (and reuse potential) between two elements by assigning the responsibility of mediation between then to an intermediate object.

[edit] Protected Variations

The Protected Variations pattern protects elements from the variations on other elements (objects, systems, subsystems) by wrapping the focus of instability with an interface and using polymorphism to create various implementations of this interface.