Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 38

UML Class Diagrams

Represent the (static) structure of the system


General In Java
Name Name
tate !aria"les
#ehavior Metho$s
Relationships #et%een Classes
&ssociation
'ermanent( structural( )has a*
oli$ line %ith arro%hea$
Depen$ency
+emporary( )uses a*
Dotte$ line %ith arro%hea$
Generali,ation
Inheritance( )is a*
oli$ line %ith open triangular arro%hea$
Implementation
Dotte$ line %ith open triangular arro%hea$
-R
&ssociation
Denotes permanent( structural relationship
-ccurs %hen state of class & contains class #
!ie% as a )has a* relationship "et%een classes
Represente$ "y soli$ line (%ith arro%hea$)
./ample
Class Car 0 Class .ngine 0
.ngine my.ngine1 2
3 3
Car )has a* .ngine
&ssociation %4 Navigation
Navigation information
Relationship "et%een classes may "e $irectional
&rro%hea$ in$icates $irection of relationship
Car class 5no%s a"out .ngine class
.ngine class $oesn6t 5no% a"out Car
&ssociation %4 Navigation
-ne7%ay association
-nly one class contains other class
Use arro%hea$ to in$icate $irection of relationship
'oint to class containe$ in 8
n$
class
./ample
Class Car 0 Class .ngine 0
.ngine my.ngine1 2
3 3
&ssociation %4 Navigation
#i7$irectional association
#oth classes contain o"9ect of other class
Use un$irecte$ soli$ e$ge (no arro%hea$s)
./ample
Class Car 0 Class .ngine 0
.ngine my.ngine1 Car myCar1
3 3
Multiplicity of &ssociations
ome relationships may "e :uantifie$
Multiplicity $enotes ho% many o"9ects the
source o"9ect can legitimately reference
Notation
; <( =( or more
> > e/actly
>??@ "et%een > an$ @( inclusive
>??; > or more
Multiplicity of &ssociations
Many7to7one
#an5 has many &+Ms( &+M 5no%s only = "an5
-ne7to7many
Inventory has many items( items 5no% = inventory
Depen$ency
Denotes $epen$ence "et%een classes
&l%ays $irecte$ (Class & $epen$s on #)
Represente$ "y $otte$ line %ith arro%hea$
& $epen$s on #
& #
Depen$ency
Cause$ "y class metho$s
Metho$ in Class & temporarily )uses a* o"9ect
of type Class #
Change in Class # may affect class &
& uses o"9ect of class #
& #
Depen$ency
Depen$ence may "e cause$ "y
Local varia"le
'arameter
Return value
./ample
Class & 0 Class # 0
# Aoo(# /) 0 2
# y B ne%()1 2
return y1 2
3 3 3
Generali,ation
Denotes inheritance "et%een classes
Can vie% as )is7a* relationship
Represente$ "y line en$ing in (open) triangle
Laptop( Des5top( 'D& inherit
state C "ehavior from Computers
Implementation
Denotes class implements Java interface
Represente$ "y $otte$ line en$ing in (open)
triangle
& implements interface #
& B
UML ./amples
Rea$ UML class $iagram
+ry to un$erstan$ relationships
./amples
'ets C o%ners
Computer $is5 organi,ation
Li"rary "oo5s
#an5ing system
Dome heating system
'rinting system
UML ./ample E !eterinary ystem
+ry to rea$ C un$erstan$ UML $iagram
UML ./ample E !eterinary ystem
+ry to rea$ C un$erstan$ UML $iagram

= or more 'ets associate$ %ith = 'et-%ner


UML ./ample E Computer ystem
+ry to rea$ C un$erstan$ UML $iagram
UML ./ample E Computer ystem
+ry to rea$ C un$erstan$ UML $iagram

= C'U associate$ %ith < or more Controllers

=7F Dis5Drives associate$ %ith = CIController

CIController is a (speciali,e$) Controller


UML ./ample E Li"rary ystem
+ry to rea$ C un$erstan$ UML $iagram
UML ./ample E Li"rary ystem
+ry to rea$ C un$erstan$ UML $iagram

= or more #oo5 associate$ %ith = or more 'ages

'atron C helf temporarily use ($epen$ on) #oo5s


UML ./ample E #an5ing ystem
+ry to rea$ C un$erstan$ UML $iagram
UML ./ample E #an5ing ystem

= #an5 associate$ %ith < or more &ccounts

Chec5ing( avings( MoneyMar5et are &ccounts


UML ./ample E Dome Deating ystem
+ry to rea$ C un$erstan$ UML $iagram
UML ./ample E Dome Deating ystem

.ach +hermostat has = Room

.ach +hermostat associate$ %ith < or more Deaters

.lectricDeater is a speciali,e$ Deater

&u"e+D=<=D is a speciali,e$ +hermostat


UML Class Diagrams Java
Different representation of same information
Name( state( "ehavior of class
Relationship(s) "et%een classes
'ractice $eriving one from the other
&ccurately $epicting relationship "et%een classes
UML Java G !eterinary ystem
UML
Java
UML Java G !eterinary ystem
UML
Java
class 'et 0
'et-%ner my-%ner1 44 = o%ner for each pet
3
class 'et-%ner 0
'et H I my'ets1 44 multiple pets for each o%ner
3
Java UML G !eterinary ystem
Java
class 'et 0
'et-%ner my-%ner1 44 = o%ner for each pet
3
class 'et-%ner 0
'et H I my'ets1 44 multiple pets for each o%ner
3
UML
Java UML G !eterinary ystem
Java
class 'et 0
'et-%ner my-%ner1 44 = o%ner for each pet
3
class 'et-%ner 0
'et H I my'ets1 44 multiple pets for each o%ner
3
UML
UML Class Diagrams Java
UML
Java
class 'et 0
'et-%ner my-%ner1 44 = o%ner for each pet
3
class 'et-%ner 0
'et H I my'ets1 44 multiple pets for each o%ner
3
UML Java G Computer ystem
UML
Java
UML Java G Computer ystem
UML
Java
class Controller 0
3
class CIController e/ten$s Controller 0
3
UML Java G Computer ystem
UML
Java
Design co$e using all availa"le information in UML2
UML Java G Computer ystem
Java
class C'U 0
Controller H I myCtlrs1
3
class Controller 0
C'U myC'U1
3
class CIController e/ten$s Controller 0
Dis5Drive H I myDrives B ne% Dis5DriveHFI1
3
Class Dis5Drive 0
CIController myCI1
3
Java UML G 'rinting ystem
Java
class Registry 0
'rintJueue fin$Jueue()1
3
class 'rintJueue 0
List printJo"s1
'rinter my'rinter1
Registry myRegistry1
voi$ ne%Jo"()1
int length()1
Resources getResource()1
3
Java UML G 'rinting ystem
Java
Class 'rinter 0
Resources myResources1
Jo" curJo"1
voi$ print()1
"oolean "usy()1
"oolean on()1
3
class Jo" 0
Jo"(Registry r) 0
2
3
3
Java UML G 'rinting ystem
UML ummary
Graphics mo$eling language
!isually represents $esign of soft%are system
Ke focuse$ on class $iagrams
Contents of a class
Relationship "et%een classes
Lou shoul$ "e a"le to
Dra% UML class $iagram given Java co$e
Krite Java co$e given UML class $iagram

You might also like