Escolar Documentos
Profissional Documentos
Cultura Documentos
Software Engineering
Introduction to GRASP
Readings
y “Applying” Chapter 17
◦ GRASP: Designing Objects with
Responsibilities
y R. Wrifs-Brock, A. McKean
◦ Object Design: Roles, Responsibilities,
and Collaborations
1
6/12/2010
Supplementary Report
Specification Sketches
NFRs
Database
Models
2
6/12/2010
Responsibility
y A contract or obligation of a classifier
y Doing Responsibilities
◦ creating an object or doing a calculation
◦ initiating action in other objects
◦ coordinating activities in other objects
y Knowing Responsibilities
◦ knowing about private encapsulated data
◦ knowing about related objects
◦ knowing about things it can derive or calculate
Example
y Sale Responsibilities
◦ Creating SalesLineItem objects
◦ Knowing its total
y Granularity of responsibilities
y Responsibilities
p and Methods
3
6/12/2010
GRASP
y 9 Patterns for assigning
responsibilities
y Patterns or principles?
◦ One person's pattern is another person's
primitive building block.
High
Cohesion
4
6/12/2010
10
5
6/12/2010
Applying Creator
Dynamic
y Model
Static Model
11
12
6
6/12/2010
13
14
7
6/12/2010
Coupling
y A measure of how strongly one
element is connected to
to, has
knowledge of, or depends on other
elements.
y Examples
◦ A subclass is strongly coupled to a superclass.
◦ An object A that calls on the operations of object
B has coupling to B's services.
15
16
8
6/12/2010
Notes on Coupling
y Why is it bad?
y Strong and weak coupling
y Coupling to unstable objects
17
9
6/12/2010
19
20
10
6/12/2010
21
Using Option 1
One controller per system
22
11
6/12/2010
23
Cohesion
y Measures how functionally related the
operations of a software element are, and also
measures how much work a software element
is doing.
y Example
◦ Big: 100 methods – 2000 SLOC
◦ Small: 10 methods – 200 SLOC
y Low Cohesion ⇔ High Coupling
24
12
6/12/2010
Cohesion Example
25
Notes on Cohesion
y Why is “low cohesion” bad?
y When lower cohesion is justified?
y How do you measure cohesion?
26
13