Академический Документы
Профессиональный Документы
Культура Документы
Chapters 15 & 16
Applying UML and Patterns
Craig Larman
Two kinds of UML Interaction Diagrams
doX
doA
doB
a found message
whose sender will not
be specified doC
doD
execution specification
bar indicates focus of
control typical sychronous message
shown with a filled-arrow line
Figure 15.7
What does vertical placement
communicate?
note that newly created
: Register : Sale
objects are placed at their
creation "height"
makePayment(cashTendered)
create(cashTendered) : Payment
authorize
Figure 15.10
Communication Diagram:
makePayment
direction of message
1.1: create(cashTendered)
:Payment
Figure 15.4
Communication (aka Collaboration)
diagrams
Objects are rectangular icons
e.g., Order Entry Window, Order, etc.
Messages are arrows between icons
e.g., prepare()
Numbers on messages indicate sequence
Also spatial layout helps show flow
Which do you prefer: sequence or communication?
Fowler doesnt use communication diagrams
Show flow clearly, but awkward modeling alternatives
UML notation for control logic has changed in UML 2
but Fowler isnt impressed
Control logic in
Interaction Diagrams
Conditional Message
[ variable = value ] : message()
Message is sent only if clause evaluates to true
Iteration (Looping)
* [ i := 1..N ]: message()
* is required; [ ... ] clause is optional
Communication diagrams add Seq. Numbers
before conditional messages or loops
Logic in sequence diagrams:
which notation do you prefer?
: Foo : Bar
xx
Figure 15.13 yy
: Foo : Bar
xx
Figure 15.14
yy
Logic in communication diagrams
message1
Figure 15.29
Loops in sequence diagrams:
which notation do you prefer?
lineItems[i] :
: Sale This lifeline box represents one
SalesLineItem
instance from a collection of many
t = getTotal SalesLineItem objects.
lineItems[i] :
: Sale
SalesLineItem
t = getTotal
loop
st = getSubtotal
Figure 15.17
Iteration in communication diagrams
t = getTotal 1 * [i = 1..n]: st = getSubtotal lineItems[i]:
: Sale
SalesLineItem
this iteration and recurrence clause indicates This lifeline box represents one instance from a
we are looping across each element of the collection of many SalesLineItem objects.
lineItems collection.
lineItems[i] is the expression to select one
element from the collection of many
SalesLineItems; the i value comes from the
message clause.
Figure 15.31
Asynchronous calls
startClock
3: runFinalization
:ClockStarter System : Class
1: create
asynchronous message
2: run
Figure 15.35
active object
:Clock
authorize authorize
doA
doX
:DebitPayment doB :Foo :CreditPayment :Bar
Figure 15.34
Chapter 16
Design Class Diagrams (DCDs)
Register Sale
Design Model ... time
1
isComplete : Boolean
DCD; software endSale() currentSale /total
perspective enterItem(...)
makePayment(...) makeLineItem(...)
Figure 16.2
Developing a Domain Class Diagram:
the NextGen POS DCD
Sale SalesLineItem
...
Two ways to show a
collection attribute
Sale SalesLineItem
1..*
time: DateTime ...
lineItems
... {ordered, List} ...
: Register : Sale
makePayment(cashTendered)
makePayment(cashTendered)
messages in interaction
diagrams indicate operations
in the class diagrams classes
identified in the
interaction
diagrams are
Register Sale declared in the
1 class diagrams
... ...
currentSale
makePayment() makePayment()
... ...
Parameters, return types optional?
readability vs. code generation
Method body pseudo-code also optional
Register
method
// pseudo-code or a specific language is OK ...
public void enterItem( id, qty )
{ endSale()
ProductDescription desc = catalog.getProductDescription(id); enterItem(id, qty)
sale.makeLineItem(desc, qty); makeNewSale()
} makePayment(cashTendered)
5) Add associations and navigability
Navigability implies visibility ofattribute
What attributes
does
ProductCatalog
implicitly contain?
How does
navigability
clarify this
design?
6) Adding dependency relationships
...
Sale
...
...
updatePriceFor( ProductDescription )
... SalesLineItem
1..* ...
lineItems
...
Composition (whole-part) relations
1 40 1 1..*
Board Square Sale SalesLineItem
Figure 16.13
Association classes
model association with attributes & operations
Company * Employs
* Person
Figure 16.16
Interfaces and Template Classes
Interface is a predefined stereotype
Templates take parameters in corner
the attribute type may be expressed in
parameterized or template K official UML, with the template binding
interfaces and classes interface syntax requiring an arrow
List or
K is a template parameter in another language, such as Java
clear()
...
Board
Figure 16.18
officially in UML, the top format is
SuperclassFoo used to distinguish the package
or name from the class name
SuperClassFoo { abstract }
unofficially, the second alternative
- classOrStaticAttribute : Int is common
+ publicAttribute : String
3 common
- privateAttribute
compartments
assumedPrivateAttribute
isInitializedAttribute : Bool = true java.awt::Font
1. classifier name
aCollection : VeggieBurger [ * ] or
attributeMayLegallyBeNull : String [0..1] java.awt.Font
2. attributes
finalConstantAttribute : Int = 5 { readOnly }
/derivedAttribute plain : Int = 0 { readOnly }
3. operations
bold : Int = 1 { readOnly }
+ classOrStaticMethod() name : String
an interface
+ publicMethod()
assumedPublicMethod()
style : Int = 0
...
DCD
- privateMethod()
shown with a
keyword
# protectedMethod()
~ packageVisibleMethod()
getFont(name : String) : Font
getName() : String
summary
constructor SuperclassFoo( Long ) ...
methodWithParms(parm1 : String, parm2 : Float)
methodReturnsSomething() : VeggieBurger
interface
Runnable
methodThrowsException() {exception IOException}
abstractMethod() Questions?
abstractMethod2() { abstract } // alternate Fruit
run() finalMethod() { leaf } // no override in subclass dependency
synchronizedMethod() { guarded } ...
...
interface
implementation
and
subclassing SubclassFoo
PurchaseOrder
... 1
...
run() order
...
...
association with Figure 16.1
multiplicities
- ellipsis means there may be elements, but not shown
- a blank compartment officially means unknown but as a
convention will be used to mean no members
Designing with interaction
and class diagrams