Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Class Diagrams
slides by Prof. C. Constantinides
addLineItem ()
endSale()
makePayment()
Use Case
System
Sequence
Diagram
Operation:
makeNewSale
...
Operation:
addLineItem
...
makeNewSale()
addLineItem(id, quantity)
endSale()
makePayment(cashTendered) Operation:
endSale
...
Operation:
makePayment
...
System
Operations
Contracts
Sequence diagrams
Sequence diagrams illustrate interactions in a
kind of fence format.
Set of all operation contracts defines system
behavior.
We will create an interaction diagram for each
operation contract.
:ClassAInstance
:ClassBInstance
message1()
message2()
message3()
3
:Sale
makePayment (cashTendered)
makePayment (cashTendered)
create (cashTendered)
:Payment
Class
:Sale
Instance
s1:Sale
Named instance
5
:Sale
makePayment()
makePayment()
create()
:Payment
Sequence diagrams
:A
:B
message1()
[color=red] calculate()
Example-Alternate Flow
(branching)
:A
:B
:C
message1()
[x<10] calculate()
[x>15] calculate()
:Sale
makePayment()
create()
p:Payment
addPayment(p)
10
:Sale
makePayment()
makePayment()
create()
:Payment
11
Return Values
Two Accepted ways of expressing return Values.
1. Using syntax returnVar = message(parameter).
2. Using a reply (or return) message at the end of
the activation bar for that method. If this is used
the return value is labeled with a description.
A use-case realization
describes how a use case
is realized in terms of
collaborating objects.
UML interaction diagrams
are used to illustrate use
case realizations.
Recall Process Sale: from
the main scenario we
identified a number of
system events
(operations)
Each system event was
then described by a
contract.
13
Register creates a
Sale by Creator.
create()
By Controller.
:Sale
create()
:SalesLineItem
SuperclassFoo
or
SuperClassFoo { abstract }
3 common
compartments
1. classifier name
2. attributes
3. operations
an interface
shown with a
keyword
interface
Runnable
run()
- classOrStaticAttribute : Int
+ publicAttribute : String
- privateAttribute
assumedPrivateAttribute
isInitializedAttribute : Bool = true
aCollection : VeggieBurger [ * ]
attributeMayLegallyBeNull : String [0..1]
finalConstantAttribute : Int = 5 { readOnly }
/derivedAttribute
+ classOrStaticMethod()
+ publicMethod()
assumedPublicMethod()
- privateMethod()
# protectedMethod()
~ packageVisibleMethod()
constructor SuperclassFoo( Long )
methodWithParms(parm1 : String, parm2 : Float)
methodReturnsSomething() : VeggieBurger
methodThrowsException() {exception IOException}
abstractMethod()
abstractMethod2() { abstract } // alternate
finalMethod() { leaf } // no override in subclass
synchronizedMethod() { guarded }
java.awt::Font
or
java.awt.Font
plain : Int = 0 { readOnly }
bold : Int = 1 { readOnly }
name : String
style : Int = 0
...
getFont(name : String) : Font
getName() : String
...
Fruit
dependency
...
...
interface
implementation
and
subclassing
SubclassFoo
PurchaseOrder
1
...
run()
...
- 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
order
...
...
association with
multiplicities
17
Register
Sale
1 Captures
date: Date
isComplete : Boolean
Sale
Register
Design:
software perspective
date: Date
isComplete : Boolean
getBalance()
endSale()
makeNewSale()
addLineItem()
makePayment()
1 Captures
becomeComplete()
isComplete()
currentSale
makeLineItem()
makePayment()
getBalance()
getTotal()
18
Navigability
Type information
Sale
Register
getBalance()
endSale()
makeNewSale()
addLineItem()
makePayment()
Captures
date: Date
isComplete : Boolean
1
becomeComplete()
isComplete()
makeLineItem()
makePayment()
getBalance()
getTotal()
19
2.
Payment
quantity
Store
address
phone
Sale
date: Date
isComplete
specification
price
id
amount: Money
SalesLineItem
quantity
20
3.
date: Date
isComplete: Boolean
makeLineItem()
:Register
3: makeLineItem(spec, quantity)
:Sale
21
4.
Register
ProductSpecification
ProductCatalog
specification: String
price: Money
id: ItemID
endSale()
addLineItem()
makeNewSale()
makePayment()
getProductSpecification()
Sale
Store
address: Address
phone: PhoneNumber
date: Date
isComplete: Boolean
becomeComplete()
makeLineItem()
makePayment()
getTotal()
SalesLineItem
Payment
amount
quantity: integer
getSubtotal()
22
:ProductCatalog
23
Illustrating attributes
Register class will probably
have an attribute pointing to a
Sale object.
Sale
Register
1
Captures
endSale()
addLineItem()
makePayment()
date: Date
isComplete : Boolean
makeLineItem()
25
Sale
Register
currentSale : Sale
...
...
...
Register
Sale
1
...
currentSale
...
...
...
thorough and
unambiguous, but some
people dislike the
possible redundancy
Register
currentSale : Sale
...
Sale
1
currentSale
...
...
26
Example of attributes as
association types
Sale
Register
date: Date
isComplete : Boolean
getBalance()
endSale()
makeNewSale()
addLineItem()
makePayment()
1 Captures
becomeComplete()
isComplete()
currentSale
makeLineItem()
makePayment()
getBalance()
getTotal()
catalog
1
ProductCatalog
addProduct()
getProductSpecification()
27
Collection attributes:
Two ways to illustrate
Sale
SalesLineItem
date: Date
lineItems: SalesLineItem [1..*]
or
lineItems: SalesLineItem [1..*] {ordered}
Sale
SalesLineItem
1..*
lineItems
{ordered, List}
An association end can optionally have
a property string like {ordered, List}
28
Store
address : Address
1 phone : PhoneNumber
Uses
ProductSpecification
1
ProductCatalog
Contains
getRegister()
Looks-in
specification : String
price : Money
id: itemID
1
1 addProduct()
getProductSpecification()
1
Houses
1..*
Describes
Sale
Register
Captures
1
getBalance()
endSale()
makeNewSale()
addLineItem()
makePayment()
Logs-completed
SalesLineItem
date : Date
isComplete : Boolean
becomeComplete()
isComplete()
makeLineItem()
makePayment()
getBalance()
getTotal()
*
Contains
1
quantity : integer
1..*
getSubtotal()
Payment
amount : Money
Paid-by
29