Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Ivan Marsic
Rutgers University
Topics
• Assigning Responsibilities to Objects
• Design Principles
• Expert Doer
• High Cohesion
• Low Coupling
• Business Policies
• Class Diagram
2
System Sequence Diagrams
We already worked with interaction diagrams: System Sequence Diagrams
: System
User Timer
«initiating actor» «offstage actor»
select function(“unlock")
enter key
verify key
start ("duration“)
User
«initiating actor»
ystem
: System
Timer
«offstage actor»
checkKey()
sk := getNext()
select function(“unlock")
start ("duration“)
6
Design: Assigning
Responsibilities
checkKey()
accessList := retrieve(params : string)
R1.
interfacePage := activate( "lock" )
render(accessList : string) ?
R2.
(a) (b)
7
Characteristics of Good Designs
• Short communication chains between the
objects
8
Design Principles
• Expert Doer Principle: that who knows should
do the task
checkKey() ok := checkKey()
setOpen(true) setOpen(true)
?
(a) (b)
• Although the Checker is the first to acquire the information about the key validity,
we decide to assign the responsibility to notify the LockCtrl to the Controller.
• This is because the Controller would need to know this information anyway—to
inform the user about the outcome of the key validity checking.
• In this way we maintain the Checker focused on its specialty and avoid assigning
too many responsibilities to it.
10
Cohesion
Low cohesion
High cohesion
11
Responsibility-Driven Design
1. Identify the responsibilities
• domain modeling provides a starting point
• some will be missed at first and identified in subsequent iterations
«html»
interfacePage : : Controller : PageMaker : DatabaseConnection
Resident Database
result
[else] page :=
warning()
13
Example …
Communicating responsibilities identified for the system function “enter key”:
Responsibility Description
Send message to Key Checker to validate the key entered by the user.
14
Unlocking Sequence Diagram
checkKey()
sk := getNext()
logTransaction(val)
enterKey()
«create»
compare(k, sk)
logTransaction( k, val )
«destroy»
dl := isDaylight()
[else] numOfAttempts++
activate( "alarm" )
[else]
k := create()
checkKey(k) loop
sk := getNext()
setValid(ok)
controlLock(k)
ok := isValid()
opt ok == true
setOpen(true)
To avoid an impression that the above design is the only one possible!!
controlLight() checkIfDaylightAndIfNotThenSetLit()
dl := isDaylight() dl := isDaylight()
compare()
activate( "light" )
logTransaction(k, val) dl := isDaylight()
«destroy»
opt dl == false
dl := isDaylight()
loop
b
checkKey(k) : DeviceCtrl : PhotoSObs
sk := getNext()
setValid(ok)
checkIfDaylightAndIfNotThenSetLit()
controlLock(k) dl := isDaylight()
ok := isValid()
The caller opt dl == false
opt ok == true
could be
Controller or
setOpen(true) Checker setLit(true)
19
Business Policies
Controller
# numOfAttemps_ : long
# maxNumOfAttempts_ : long
+ enterKey(k : Key)
– denyMoreAttempts() KeyChecker
1
DeviceCtrl
1 logger
# devStatuses_ : Vector
Logger + activate(dev : string) : boolean
+ deactivate(dev :string) : boolean
+ logTransaction(k : Key) + getStatus(dev : string) : Object
21
Traceability Matrix (3)
Mapping: Domain model to Class diagram
Software Classes
«html» interfacePage
DatabaseConnection
SearchRequest
Controller-SS1
Controller-SS2
PhotoSObsrv
KeyChecker
KeyStorage
PageMaker
DeviceCtrl
Logger
Key
Domain Concepts
Controller-SS1 X
StatusDisplay
Key X
KeyStorage X
KeyChecker X
HouseholdDeviceOperator X
IlluminationDetector X
Controller-SS2 X
SearchRequest X
InterfacePage X
PageMaker X
Archiver
DatabaseConnection X
Notifier
InvestigationRequest
22
Types of Object Communication
SS11
AA BB
SS22
AA BB PP
SSNN
(a) (b) (c)
23