In OOAD, assignment of responsibilties to classes and objects is an inportant task and GRASP caters the guidelines for such assignments.
To understand what patterns are and what is GRASP.
Introduction and background
The verb “Software Pattern” is present for couple of decades and it came into limelight with GOF (Gang of Four) publishing their book “Design Patterns: Elements of Reusable Object-Oriented Software” in 1994. This book put forth the catalog of well described design patterns for object oriented software programs. C++ and JAVA world has been aware of such patterns for long time.
Patterns are inviting considerable attention in recent years through workshops, seminars, forums, papers in journals and worth to mention the books.
With .NET catching the eye and also attaining stability, the patterns are becoming the regular term in their world. .NET framework itself is developed with pattern orientation and there are so many good examples in the framework itself.
So what’s so special and exiting about patterns? Patterns can be termed as comprising the efforts to build on collective experience of skilled designers and software engineers. These experts have found solutions to many recurring software design problems and such solutions are captured in patterns which are understandable, well written and practical forms.
Patterns do not usually contain new ideas but highlight or codify existing knowledge and basic principles.
What is Pattern?
It is common that when experts works on particular problems, they need not reinvent the wheel i.e. they need not find a complete new solution that is completely different from existing solutions. Rather they remember the similar problem and it solution and reuse the core of it for solving new problem. They think in terms of “Problem Solution” pairs. Abstracting from such pairs and churning out the commonalities leads to patterns.
Each pattern is three-part rule which expresses a relation between a certain context, a problem and a solution.
Patterns have names and they facilitate communication- common vocabulary and understanding-easy to remember whole concept in a nutshell.
Craig Larman coined these terms for the first time.
stands for General Responsibility Assignment Software Patterns.
The mnemonic meaning could be “successful OOAD (Object Oriented Analysis & Design) requires grasping (understanding)”.
General: = Abstract i.e. widely applicable for variety of situations
Responsibility: = Obligations, duties –information object performing duty of holding information, computational object performing duty of computation
Assignment: = Giving a responsibility to a module- capability to carry out responsibility structure and methods
Software: = Computer code
Patterns: = Regularities, templates, abstraction
Assigning responsibilities to objects is always is major task in designing the software’s. Specifically it’s always a challenge to decide which object carry out what job (responsibilities) and quality of software design largely depended upon such responsibilities assignment.
Poor choices about such responsibities leads to fragile systems and components which are hard to maintain, understand, reuse or extend.
Let’s define responsibility:
Responsibility is defined as a contract or obligation of a type or class and is related to behavior.
There are 2 types of responsibilities
1. Knowing - responsibilities of an object include
a. Knowing about private encapsulated data-member data
b. Knowing about related objects
c. Knowing about things it can derive or calculate
2. Doing - responsibility of an object include
a. Doing something itself-assign, calculate, create
b. Initiating action in other objects
c. Controlling and coordinating activities in other objects
The responsibilities would be translated into classes and their methods and it is largely influenced by the granularity of the responsibility. Don’t confuse the responsibility as a method in a class even though they are implemented using methods which either act alone or collaborate with other methods and objects. Object-oriented principles are applied by experienced developers/experts in deciding general assignment of responsibilities.
GRASP patterns describe fundamental principles of assigning responsibilities to objects and it has following principles and patterns in the family
- Information Expert
- Low Coupling
- High Cohesion
- Pure Fabrication
- Protected Variations.
We discussed the software patterns, the GOF and started on GRASP. These concepts are bit difficult to understand as these are not part of day to day vocabulary of developer community. To build better and robust software systems which are easy to maintain, reuse, the programmer needs to be aware of such concepts, principles which help him to solve the problems to the core. Especially large or enterprise systems can’t last long if they are built without giving attentions to patterns and patter oriented development.
Let’s delve into specific patterns in the next part of this article.
Applying UML and Patterns