GRASP 1 Flashcards
What is a Responsibility and what types of responsibilities are there?
A contract or obligation of a classifier.
Knowing and Doing Responsibilities
What do Doing responsibilities include?
directly—e.g. create object, perform calculation
initiate action in other objects
control and coordinate activities in other objects
What do knowing responsibilities include?
Knowledge of: Private encapsulated data Related objects Derivable or calculable items Can be inferred from the domain model b/c of attributes and accossiations
What does RDD stand for?
Responsibility driven design
What is RRD?
RDD sees an OO Design as a community of collaborating responsible objects.
It involves assigning responsibilities to classes which should be based on proven principles.
What does GRASP stand for?
General Responsibility Assignment Software Patterns (or Principles).
Its a Learning Aid for RDD
What are the 9 GRASP patterns?
- Creator
- Information Expert
- Low Coupling
- High Cohesion
- Controller
- Polymorphism
- Indirection
- Pure Fabrication
- Protected Variations
What problem does the Creator pattern aim to resolve?
Who should be responsible for creating a new instance of some class?
Creation of objects:
One of the most common OO activities
Useful to have a general principle to deal with this
Want outcomes with low coupling, increased clarity, encapsulation, and reusability
What solution does the Creator pattern propose?
Assign class B responsibility to create instances of class A if one of these is true (the more the better):
B “contains” or compositely aggregates A.
B records A.
B closely uses A.
B has the initializing data for A that will be passed to A when it is created. Thus B is an Expert with respect to creating A.
If >1 applies, choose B which aggregates/containsA.
What are the contraindications of the creator pattern?
Creation of significant complexity, e.g.
o recycling instances for performance.
o instances from A1, A2, …, based on property
In these cases, delegate to helper class in the form of a Concrete Factory or Abstract Factory.
What problem does the Information Expert pattern aim to resolve?
What is a general principle of assigning responsibilities to objects?
Design model:
May have 100s or 1000s of software classes
May have 100s or 1000s of responsibilities
Useful to have a general principle to guide choice of assignment
Want outcomes that are easier to understand, maintain, extend, and reuse
What solution does the Information expert pattern propose?
Assign responsibility to the information expert—the class that has the informationnecessary to fulfil the responsibility. Start assigning responsibilities by clearly stating the responsibility. Look in Domain Model or Design Model? 1. If relevant classes in Design, look there first. 2. Otherwise look in Domain, and use or expand to inspire creation of design classes.
What are the contraindications of the Information Expert pattern?
Suggested solution can result in poor coupling and cohesion
Example:
Need to store objects in a database (DB)
Each class is an expert on what needs to be stored
Add DB handling to each class?
No: DB elements and other class elements not cohesive; couples all classes with DB services
Separate application logic and DB logic (DB Expert)
What problem does the Low Coupling pattern aim to resolve?
How to support low dependency, low change impact, and increased reuse?
Problems for a class with high coupling:
Forced changes: result of changes in related classes
Harder to understand in isolation
Harder to reuse, as harder to isolate
What solution does the Low Coupling pattern propose?
Assign responsibility so that coupling remains low. Use this principle to evaluate alternatives.