Analysis Patterns
Analysis Patterns
1
GRASP*: Designing Objects with
Responsibilities
2
Responsibilities and Methods
3
Responsibilities and Methods
4
Responsibilities and Methods
5
Responsibilities and Interaction
Diagrams
Within the UML artifacts, a
common context where
these responsibilities
:Sale (implemented as methods)
are considered is during the
creation of interaction
makePayment(…)
diagrams.
create(…) Sale objects have been
:Payment given the responsibility to
create Payments, handled
with the makePayment
method.
6
Patterns
7
Information Expert (or Expert)
8
Information Expert (or Expert)
9
Information Expert (or Expert)
It is necessary to know
Sale
date about all the
time SalesLineItem
Contains
instances of a sale and
the sum of the
1..*
SalesLineItem Described-by Product
subtotals.
quantity * 1
Specification A Sale instance
description contains these, i.e. it is
price
itemID an information expert
for this responsibility.
10
Information Expert (or Expert)
This is a partial
t := getTotal() interaction diagram.
:Sale
11
Information Expert (or Expert)
12
Information Expert (or Expert)
To fulfil the
t := getTotal() responsibility of
:Sale
knowing and answering
its subtotal, a
SalesLineItem needs to
1 *: st := getSubtotal()
know the product price.
:SalesLineItem The ProductSpecification
is the information
1.1: p := getPrice() expert on answering its
:ProductSpecification price.
13
Information Expert (or Expert)
14
Creator
15
Creator
16
Creator
This assignment of
responsibilities requires
:Sale that a makeLineItem
method be defined in
makeLineItem(quantity) Sale.
create(quantity)
:SalesLineItem
17
Low Coupling
Coupling: it is a measure of how strongly one element is
connected to, has knowledge of, or relies upon other elements.
A class with high coupling depends on many other classes
(libraries, tools).
Problems because of a design with high coupling:
Changes in related classes force local changes.
18
Low Coupling
Assume we need to
create a Payment
instance and associate
it with the Sale.
:Register :Payment :Sale What class should be
responsible for this?
By Creator, Register is
a candidate.
19
Low Coupling
20
Low Coupling
21
Low Coupling
22
High Cohesion
23
High Cohesion
24
High Cohesion
An alternative design
delegates the Payment
:Register :Sale creation responsibility
to the Sale, which
makePayment() supports higher
cohesion in the
makePayment() Register.
create() This design supports
:Payment
high cohesion and low
coupling.
25
High Cohesion
26
High Cohesion
27
Controller
28