GRASP 1 Flashcards

1
Q

What is a Responsibility and what types of responsibilities are there?

A

A contract or obligation of a classifier.

Knowing and Doing Responsibilities

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What do Doing responsibilities include?

A

 directly—e.g. create object, perform calculation
 initiate action in other objects
 control and coordinate activities in other objects

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What do knowing responsibilities include?

A
Knowledge of:
 Private encapsulated data
 Related objects
 Derivable or calculable items
Can be inferred from the domain model b/c of attributes and accossiations
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What does RDD stand for?

A

Responsibility driven design

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is RRD?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What does GRASP stand for?

A

General Responsibility Assignment Software Patterns (or Principles).
Its a Learning Aid for RDD

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are the 9 GRASP patterns?

A
  • Creator
  • Information Expert
  • Low Coupling
  • High Cohesion
  • Controller
  • Polymorphism
  • Indirection
  • Pure Fabrication
  • Protected Variations
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What problem does the Creator pattern aim to resolve?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What solution does the Creator pattern propose?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are the contraindications of the creator pattern?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What problem does the Information Expert pattern aim to resolve?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What solution does the Information expert pattern propose?

A
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.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What are the contraindications of the Information Expert pattern?

A

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)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What problem does the Low Coupling pattern aim to resolve?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What solution does the Low Coupling pattern propose?

A

Assign responsibility so that coupling remains low. Use this principle to evaluate alternatives.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What are the contraindications of the Low Coupling pattern?

A

High coupling to stable elements is rarely a problem
Example:
 Standard Java Libraries can be used extensively without concern as their use does not generate concerns relating to stability, understanding or reuse.
Note: Coupling is essential. We are choosing where it can be kept low without compromising other design aspects.

17
Q

What is coupling?

A

Measure of how strongly one element is connected to, has knowledge of or relies on others.

18
Q

What problem does the Controller pattern aim to resolve?

A

What first object beyond the UI layer receives and coordinates (“controls”) a system operation?
System operations:
 major input events
 appear on System Sequence Diagrams (SSDs)

19
Q

What solution does the Controller pattern propose?

A

Assign responsibility to a class representing one of:
 the overall “system”, a “root” object, a device the software is running within, or a major subsystem
o façade controller
 a use case scenario that deals with the event, e.g. (Handler|Coordinator|Session)
o use case or session controller

20
Q

What are the contraindications of the Controller pattern?

A

Bloated controller: too many responsibilities, low cohesion, unfocussed
o Single controller class for all system events
 Soln: add more controllers (façade → use case)
o Controller too complicated, contains too much or duplicated information: violates Information Expert and High Cohesion
 Soln: delegate!

21
Q

What problem does the High Cohesion pattern aim to resolve?

A

How to keep objects focussed, understandable, and manageable, and as a side effect, support Low Coupling?
(functional) cohesion: A measure of how strongly (functionally) related and focussed the responsibilities of an element are

22
Q

What solution does the High Cohesion pattern propose?

A

Assign a responsibility so that cohesion remains high. Use this to evaluate alternatives.

23
Q

What are the contraindications of the High Cohesion pattern?

A

Lower cohesion is sometimes justified to meet non-functional requirements
Example:
To meet performance requirements, larger, less cohesive classes are used to reduce processing overheads (e.g. transmission, storage, retrieval)

Note: Coupling and cohesion are fundamental design properties which are interdependent: both must be considered together.

24
Q

What is (functional) cohesion?

A

A measure of how strongly (functionally) related and focussed the responsibilities of an element are

25
Q

What are some issues of classes that have low cohesion?

A

 Hard to comprehend
 Hard to reuse
 Hard to maintain
 Delicate; constantly affected by change