UML Class Diagrams (more notation)
Jan 02, 2016
UML Class Diagrams(more notation)
Class Diagrams
• Used for static modeling, i.e. modeling the static aspects of system
• Design class diagram (DCD) – used in design model, incorporates more detail than class diagram used for domain model
Fig. 16.2
Register
...
endSale()enterItem(...)makePayment(...)
Sale
timeisComplete : Boolean/total
makeLineItem(...)
Register
...
Sale
timeisComplete : Boolean/total
Captures
1
11Domain Model
conceptual perspective
Design Model
DCD; software perspective
currentSale
Attributes
• How to show:– Attribute text– Association line labeled
• Attribute text notation:
name : type
Use +/- for visibility of attribute
Fig. 16.3
Register
...
...
Sale
...
...
1
Register
currentSale : Sale
...
Sale
...
...
using the attribute text notation to indicate Register has a reference to one Sale instance
using the association notation to indicate Register has a reference to one Sale instance
OBSERVE: this style visually emphasizes the connection between these classes
currentSale
Register
currentSale : Sale
...
Sale
...
...
1thorough and unambiguous, but some people dislike the possible redundancy
currentSale
Attribute as association
• Association line (in design model):– Navigability arrow– Multiplicity– Role name– No association name
Fig. 16.2
Register
...
endSale()enterItem(...)makePayment(...)
Sale
timeisComplete : Boolean/total
makeLineItem(...)
Register
...
Sale
timeisComplete : Boolean/total
Captures
1
11Domain Model
conceptual perspective
Design Model
DCD; software perspective
currentSale
Fig. 16.4
the association name, common when drawing a domain model, is often excluded (though still legal) when using class diagrams for a software perspective in a DCD
Register
id: Int
...
Sale
time: DateTime
...
1
currentSale
Register
id : Int
Sale
time : DateTime
Captures-current-sale1 1UP Domain Modelconceptual perspective
UP Design ModelDCD
software perspective
Attributes
Guideline: use attribute text for data type objects, use association lines for more substantial objects . . .
Fig. 16.5
Register
id: Int
...
Sale
time: DateTime
...
1applying the guideline to show attributes as attribute text versus as association lines
Store
address: Addressphone: PhoneNumber
...
1
Register has THREE attributes:1. id2. currentSale3. location
currentSale
location
Fig. 16.6
notice that an association end can optionally also have a property string such as {ordered, List}
Sale
time: DateTime
...
SalesLineItem
...
...
1..*lineItems
{ordered, List}
Sale
time: DateTimelineItems : SalesLineItem [1..*] orlineItems : SalesLineItem [1..*] {ordered}
...
SalesLineItem
...
...
Two ways to show a collection attribute
Fig. 16.7
Register
...
endSale()enterItem(id, qty)makeNewSale()makePayment(cashTendered)
«method»// pseudo-code or a specific language is OKpublic void enterItem( id, qty ){ ProductDescription desc = catalog.getProductDescription(id); sale.makeLineItem(desc, qty);}
Fig. 16.12
«interface»Timer
getTime()
Clock1
...
getTime()... lollipop notation indicates Clock3 implements
and provides the Timer interface to clients
Timer is a provided interface
Timer
Clock3
...
getTime()...
Window2
Window3
dependency line notation
Window2 has a dependency on the Timer interface when it collaborates with a Clock2 object
socket line notation
Window3 has a dependency on the Timer interface when it collaborates with a Clock3 object
Window1 Timer
socket line notation
Window1 uses the Timer interface
it has a required interface
Clock2
...
getTime()...
Clock1 implements and provides the Timer interface
Timer
Dependencies
• Dependency relationship:client object has knowledge of other object
• Dependency line used in UML to show:– Global visibility– Parameter variable– Local variable– Static method
Fig. 16.9
SalesLineItem
...
...
ProductDescription
...
...
1..*lineItems
Sale
...
updatePriceFor( ProductDescription )...
the Sale has parameter visibility to a ProductDescription, and thus some kind of dependency
Fig. 16.10
System
...
runFinalization()...
Foo
...
doX()...
the doX method invokes the runFinalization static method, and thus has a dependency on the System class
Composition
• Two closely related concepts: – Aggregation – part/whole– Composition – stronger form of part/whole
(Note: for our purposes we will not make the distinction and just refer to it as composition.)
• Notation:– Use (closed) diamond– Do not label association
Fig. 16.13
Finger0..7
Hand
composition
1
Square40
Board1
SalesLineItem1..*
Sale1
composition means -a part instance (Square) can only be part of one composite (Board) at a time
-the composite has sole responsibility for management of its parts, especially creation and deletion
Qualified Association
• Qualified association– Provide a name for one end of an association– Usually reduces multiplicity from many to one– Names an item within a context to show
uniqueness– Example: File – Directory: use a filename as
a qualifier
Fig. 16.15
ProductCatalog
ProductDescription
itemID Contains
ProductCatalog
ProductDescription
Contains
1..*
multiplicity reduced to 1
(a)
(b)
qualifier
1
11
Association Class
• Association class– Allows attributes that more naturally belong to
association than to either class– Example: Company – Person with
association Employs, Salary more naturally belongs to association than to either of classes
Fig. 16.16
salarystartDate
Employment
EmploysCompany Person**
a person may have employment with several companies