Category Archives: GRASP

GRASP

What is GRASP?

GRASP, standing from “General Responsibility Assignment Software Patterns” is a design pattern in object-oriented software development used to assign responsibilities for different modules of code.

The different patterns and principles used in GRASP are controller, creator, indirection, information expert, low coupling, high cohesion, polymorphism, protected variations, and pure fabrication. GRASP helps us in deciding which responsibility should be assigned to which object/class.

The following are the main design principle

  1. Creator
  • Who creates an Object? Or who should create a new instance of some class?
  • “Container” obejct creates “contained” objects.
  • Decide who can be creator based on the objects association and their interaction.

2. Expert

  • Provided an object obj, whoch responsibilities can be assigned to obj?
  • Expert principle says that asign those responsibilities to obj for whoch obj has the information to fultill that responsibility.

3. Low Coupling

  • How strongly the objects are connected to each other?
  • Coupling – object depending on other object.
  • Low Coupling – How can we reduce the impact of change in depended upon elements on dependant elements.
  • Two elements can be coupled, by following if:
    • One element has aggregation/composition or association with another element.
    • One element implements/extends other element.

4. High Cohesion

  • How are the operations of any element are functionally related?
  • Related responsibilities in to one manageable unit.
  • Prefer high cohesion
  • Benefits
    • – Easily understandable and maintainable.
    • – Code reuse
    • – Low coupling

5. Controller

  • Deals with how to delegate the request from the UI layer objects to domain layer objects.
  • It delegates the work to other class and coordinates the overall activity.
  • We can make an object as Controller, if
    • Object represents the overall system (facade controller)
    • Object represent a use case, handling a sequence of operations

6. Polymorphism

  • How to handle related but varying elements based on element type?
  • Polymorphism guides us in deciding which object is responsible for handling those varying elements.
  • Benefits: handling new variations will become easy.

7. Pure Fabrication

  • Fabricated class/ artificial class – assign set of related responsibilities that doesn’t represent any domain object.
  • Provides a highly cohesive set of activities.
  • Behavioral decomposed – implements some algorithm.
  • Benefits: High cohesion, low coupling and can reuse this class.

8. Indirection

  • How can we avoid a direct coupling between two or more elements.
  • Indirection introduces an intermediate unit to communicate between the other units, so that the other units are not directly coupled.
  • Benefits: low coupling, e.g Facade, Adapter, Obserever.

9. Protected variation

  • How to avoid impact of variations of some elements on the other elements.
  • It provides a well defined interface so that the there will be no affect on other units.
  • Provides flexibility and protection from variations.

I chose to talk about GRASP because as a computer science major interested in software development, I was curious to learn more about this and how GRASP is used to assign responsibilities for different modules of code, how it provides a means to solve organizational problems.

rao.pdf (colorado.edu)

GRASP (object-oriented design) – CodeDocs

From the blog CS@Worcester – Gracia's Blog (Computer Science Major) by gkitenge and used with permission of the author. All other rights reserved by the author.