Lec-5 Software Design
Lec-5 Software Design
Lec-5 Software Design
Business Policies
Class Diagram
3 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“)
Key Checker, based on entered key-code and stored valid keys message: ???
checkKey()
accessList := retrieve(params : string)
R1.
interfacePage := activate( "lock" )
render(accessList : string) ?
R2.
(a) (b)
How Data Travels
Option A:
“expert” (Key Checker) passes the information (key validity) to another object (Controller)
which uses it to perform some work (activate the lock device)
Option B:
“expert” (Key Checker) directly uses the information (key validity)
to perform some work (activate the lock device)
Advantage:
key-code key-code activation-params
Shorter communication chain
Controller Checker LockCtrl
Drawback:
Extra responsibility for Checker
“expert” on key validity
10 Characteristics of Good
Designs
Short communication chains between the objects
method_1() method_1()
method_2()
…
method_N()
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.
13 Cohesion
Low cohesion
High cohesion
14 Responsibility-Driven
1. IdentifyDesign
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()
Responsibility Description
Send message to Key Checker to validate the key entered by the
user.
Send message to DeviceCtrl to disarm the lock device.
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()
c
k : Key : Checker : KeyStorage : DeviceCtrl : PhotoObsrv : Logger
: DeviceCtrl : PhotoSObs
k := create()
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)
Are We Done w/ UC-1:
Unlock ?
Didn’t check that the user is at the right door
Missing: Managing access rights
Didn’t distinguish critical and non-critical functions
For example, what if logTransaction() call to Logger does
not return, e.g., no access to database (network outage)
or disk-space full ?
Missing: Independent execution of non-critical functions
Adding new household devices causes major
design changes
Business rules are interleaved with authentication
and device management, but business rules are
most likely to change
Etc.
23 Business Policies