uml class diagrams (more notation)

22
UML Class Diagrams (more notation)

Upload: paulette-lemaire

Post on 02-Jan-2016

40 views

Category:

Documents


0 download

DESCRIPTION

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. Attributes. How to show: Attribute text - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: UML Class Diagrams (more notation)

UML Class Diagrams(more notation)

Page 2: 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

Page 3: UML Class Diagrams (more notation)

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

Page 4: UML Class Diagrams (more notation)

Attributes

• How to show:– Attribute text– Association line labeled

• Attribute text notation:

name : type

Use +/- for visibility of attribute

Page 5: UML Class Diagrams (more notation)

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

Page 6: UML Class Diagrams (more notation)

Attribute as association

• Association line (in design model):– Navigability arrow– Multiplicity– Role name– No association name

Page 7: UML Class Diagrams (more notation)

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

Page 8: UML Class Diagrams (more notation)

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

Page 9: UML Class Diagrams (more notation)

Attributes

Guideline: use attribute text for data type objects, use association lines for more substantial objects . . .

Page 10: UML Class Diagrams (more notation)

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

Page 11: UML Class Diagrams (more notation)

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

Page 12: UML Class Diagrams (more notation)

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);}

Page 13: UML Class Diagrams (more notation)

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

Page 14: UML Class Diagrams (more notation)

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

Page 15: UML Class Diagrams (more notation)

Fig. 16.9

SalesLineItem

...

...

ProductDescription

...

...

1..*lineItems

Sale

...

updatePriceFor( ProductDescription )...

the Sale has parameter visibility to a ProductDescription, and thus some kind of dependency

Page 16: UML Class Diagrams (more notation)

Fig. 16.10

System

...

runFinalization()...

Foo

...

doX()...

the doX method invokes the runFinalization static method, and thus has a dependency on the System class

Page 17: UML Class Diagrams (more notation)

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

Page 18: UML Class Diagrams (more notation)

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

Page 19: UML Class Diagrams (more notation)

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

Page 20: UML Class Diagrams (more notation)

Fig. 16.15

ProductCatalog

ProductDescription

itemID Contains

ProductCatalog

ProductDescription

Contains

1..*

multiplicity reduced to 1

(a)

(b)

qualifier

1

11

Page 21: UML Class Diagrams (more notation)

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

Page 22: UML Class Diagrams (more notation)

Fig. 16.16

salarystartDate

Employment

EmploysCompany Person**

a person may have employment with several companies