madhavrao… » GRASP by Craig Larman

GRASP by Craig Larman

GRASP stands for General Responsibility Assignment Software Patterns. It is used as guidelines for assigning responsibility to classes and objects in Object Oriented Design. GRASP describes fundamental principles of object design and responsibilities assignment, expressed as patterns.

There are nine patterns defined in GRASP

  1. Information Expert
  2. Creator
  3. High Cohesion
  4. Low Coupling
  5. Controller
  6. Polymorphism
  7. Indirection
  8. Pure Fabrication
  9. Protected Variance

GRASP

Information Expert(221): Assign the responsibility to the information expert - the class that has the information necessary to fulfill the responsibility.

It answers following question in design:

  1. What is the general principle of assigning responsibility to objects?

Creator(226): Assign Class B the responsibility to create an instance of Class A if one or more of the following is true:

  1. B aggregates A objects
  2. B contains A objects
  3. B record instances of A objects
  4. B closely uses A objects
  5. B has the initializing data that will be passed to A when it is created.

It answers following question in design:

  1. Who should be responsible for creating a new instance of some class?

Low Coupling(229): Assign a responsibility so that coupling remains low.

It answers following question in design:

  1. How to support low dependency, low change impact and increased reuse?

To know more about coupling and types of coupling Click here

High Cohesion(232): Assign a responsibility so that cohesion remains high.

It answers following question in design:

  1. How to keep complexity manageable?

To know more about cohesion and types of cohesion Click here

Controller(237): Assign the responsibility for receiving or handling a system event message to a class representing one of the following choices:

  1. Represents the overall system, device, or subsystem (facade controller).
  2. Represents a use case scenario within which the system event occurs, often named <Use Case Name>Handler, <Use Case Name>Coordinator, or <Use Case Name>Session (use case or session controller)

It answers following question in design:

  1. Who should be responsible for handling an input system event?

Polymorphism(326): When related alternatives  or behaviors vary by type (class), assign responsibility for the behavior - using polymorphic operations - to the type for which the behavior varies.

Corollary: Do not test for the type of an object and use conditional logic to perform varying alternatives based on type.

It answers following question in design:

  1. How to handle alternatives based on type?
  2. How to create pluggable software components?

Pure Fabrication(329):Assign a highly cohesive set of responsibilities to an artificial or convenience class that does not represents a problem domain concept - something made up to support high cohesion, low coupling and reuse.

It answers following question in design:

  1. What object should have responsibility, when you do not want to violate high cohesion and low coupling or other goals, but solutions offered by Expert are not appropriate?

Indirection(332): Assign the responsibility to an intermediate object to mediate between other components or services so that they are not directly coupled. The intermediary creates an indirection between the other components.

It answers following questions in design:

  1. Where to assign a responsibility, to avoid direct coupling between two (or more) things?
  2. How to de-couple objects so that low coupling is supported and reuse potential remains higher?

Protected Variations(334):Identify points of predicted variation or instability; assign responsibility to create a stable interface around them.

It answers following questions in design:

  1. How to design objects, sub-systems and systems, so that the variations or instability in these elements does not have un-desirable impact on other element?

Leave a comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <blockquote cite=""> <code> <em> <strong>