5
A Brief Guide to the UML Class Diagrams Introduction The Unified Modeling Language (UML) is a graphical language for creating diagrams that are useful in t he software development process The UML provides a set of standard graphical s!m"ols and t he rules for com"ining them The UML is process and implementation language independent The UML provides s!m"ols to support various views of the s!stem #n all$ there are nine diagram t!pes included in the UML% Class diagrams$ &"'ect diagrams$ Use case diagrams$ euence diagrams$ Colla"oration diagrams$ tate*chart diagrams$ Activit! diagrams$ Component diagrams$ and Deplo!ment diagrams #n this guide$ we will "e concerned with class diagrams$ which provide a structural view of the s!stem Class Diagram s Class diagrams are perhaps the most common t!pe o f diagram used in modeling o"'ect*oriented s!stems A class diagram shows a set of classes$ interfaces$ colla"orations$ and dependencies #n addition$ notes and constraints can appear on a class diagram +ou use class diagrams to show the static structure of !our s!stem A class is repr esented "! a "o, that is di vided hori-ontall! into three secti ons The top section contains the class name$ the middle section contains the class attri"utes and the  "ottom section contains the class methods An e,ample of a class diagram for a Time class is shown "elow hour minute second setTime() displayMilitaryTime() displayStandardTime() Time Class Name The class name appears in t he top section of the cl ass "o, and consists of t e,t The class name is a noun or noun phrase T!picall!$ the first l etter of each word in t he  phrase is capitali-ed * . *

A Brief Guide to UML Class Diagrams

Embed Size (px)

Citation preview

8/13/2019 A Brief Guide to UML Class Diagrams

http://slidepdf.com/reader/full/a-brief-guide-to-uml-class-diagrams 1/5

8/13/2019 A Brief Guide to UML Class Diagrams

http://slidepdf.com/reader/full/a-brief-guide-to-uml-class-diagrams 2/5

ClassAttributes

The middle section of the class "o, contains the class attri"utes An attri"ute

represents some propert! of the class The attri"ute name consists of te,t and is a nounor noun phrase T!picall!$ the first letter of each word in the phrase is capitali-ed$

e,cept the first +ou can$ optionall!$ specif! the t!pe of the attri"ute and possi"l! a

default value /or e,ample$ to specif! that the attri"ute hour is of t!pe integer and hasan initial value of .0$ replace hour in the a"ove diagram with hour : Integer = 12 

Collections (or arra!s) of attri"utes are indicated "! giving the multiplicit! 1efer to

the discussion of multiplicit! in the Association section "elow  Nota Bene: By

 specifying the type and default values, you are increasing the information content ofthe diagram at the possible expense of cluttering the diagram. This same comment is

applicable to other optional information.

ClassMethods

The "ottom section of the class "o, contains the class methods A method is ana"straction of something that an o"'ect can do$ or have done to it The method name

consists of te,t and is a ver" or ver" phrase$ followed "! left and right parenthesis

T!picall!$ !ou capitali-e the first letter of each word in the name$ e,cept the first +oucan$ optionall!$ specif! the names$ t!pes and default of all method arguments as well

as the return t!pe of functions /or e,ample$ a full specification of the setTime() 

method might loo2 li2e  setTime( newour : Integer = 12! newMinute : Integer = "! new#econd : Integer = " )

$isibilit% The UML provides s!m"ols to indicate the visi"ilit! of attri"utes and methods Thefollowing s!m"ols$ when place immediatel! "efore either an attri"ute name or method

name$ define the visi"ilit! of the attri"ute or name%&  pu"lic'  private

 protected

/or e,ample$ to give the attri"ute minute protected visi"ilit!$ !ou would write minute

#coe +ou can specif! the scope of an attri"ute using the UML B! default$ an attri"ute has

instance scope That is$ each o"'ect created from the class has its own value for the

attri"ute +ou can give an attri"ute class scope$ "! underlining the attri"ute name (andt!pe and default value if present) The most common use for class scope is to share a

 private varia"le among all instances of the class +ou might do this$ for e,ample$ if

!ou needed to give each instance a uniue identifier

*elationshis The UML provides graphic s!m"ols to represent the following relationships%• Dependenc!

• Association

• Generali-ation

 "etween classes

* 0 *

8/13/2019 A Brief Guide to UML Class Diagrams

http://slidepdf.com/reader/full/a-brief-guide-to-uml-class-diagrams 3/5

Deendenc% A dependenc! is a relationship "etween two classes in which a change to one$ called

the independent class$ causes a change in the other$ called the dependent class Adependenc! is represented "! a dashed line from the dependent class to the

independent class /or e,ample$ if !ou have a CD+la%er  pla!er class and a 

*emoteControl class$ !ou would indicate the dependenc! "! the following diagram

CDPlayer RemoteControl

Association An association is a relationship that specifies that the o"'ects of one class are

connected to o"'ects of another class An association is represented "! a solid lineconnecting the two classes /or e,ample$ suppose !ou have an ,mlo%ee class and a

Coman% class An association is depicted "! the following diagram

1 .. *Employee Company

*

The notations a"ove the solid connecting line indicate the multiplicit!$ or how man!

The a"ove diagram indicates that an instance of the ,mlo%ee class can wor2 for man!

companies and that an instance of the Coman% class has one or more emplo!eesome e,amples of multiplicities and their meaning are%

- e,actl! four 

1 .. / one to three

* man!

The same notation is used to indicate a collection or arra! of attri"utes /or e,ample$

ort0- : #erial+ort

indicates that there are 3 ports of t!pe erial&4ort

&ne particular one*to*man! association (aggregation) freuentl! arises in o"'ect*oriented modeling% the 5whole6part7 relationship An aggregation is represented "! a

solid line connecting the two classes$ with an open diamond at the end of the line

ad'acent to the 5whole7 class An e,ample is the aggregation of famil! mem"erswithin a household The UML diagram is shown "elow

Household amily Mem!er  

* 8 *

8/13/2019 A Brief Guide to UML Class Diagrams

http://slidepdf.com/reader/full/a-brief-guide-to-uml-class-diagrams 4/5

There is a variation of aggregation$ which is called composition Composition is a

relationship that has strong ownership and simultaneit! of lifetimes of the classesThat is$ if the part class "elongs to 'ust one whole class and cannot e,ist outside the

whole o"'ect$ the relationship is composition An aggregation is represented "! a solid

line connecting the two classes$ with an solid diamond at the end of the line ad'acent tothe 5whole7 class An e,ample of composition is the relationship "etween a college

and its departments The UML diagram is shown "elow

Colle"e Department

3enerali4ation

A generali-ation is a relationship "etween a general class and a more specific class

Generali-ation is the inheritance relationship A generali-ation is represented "! an

arrow$ with an unfilled head$ from the specific class (derived class) to the general class("ase class) /or e,ample$ suppose !ou have a 3raduate#tudent class and a #tudent 

class The generali-ation is depicted "! the following diagram

#raduateStudent Student

 

Notes A note is used to place comments on the class diagram #f the note applies to a specific

item on the diagram$ connect the note with the item "! a dashed line An e,ample of anote

See al"or.doc

 $or a description

o$ this al"orithm

Constraints Constraints are specific conditions that must "e true for the model to "e validConstraints are enclosed in "races 9 : /or e,ample$ suppose that we had a

+la%ingCard class and one of the properties is the suit ;e would li2e to constrain suit

to hold onl! the values% clubs$ diamonds$ hearts$ or sades An e,ample of a

constraint is

...

suit % & clu!s' diamonds' hearts' spades

...

...

+la%ingCard

Constraints can appl! to other items in the diagram$ in addition to attri"utes

* 3 *

8/13/2019 A Brief Guide to UML Class Diagrams

http://slidepdf.com/reader/full/a-brief-guide-to-uml-class-diagrams 5/5

#ummar% This "rief guide is onl! an introduction to class diagrams< it is "! no means complete

/urther more$ class diagrams are "ut one of the nine diagrams supported "! the UML/or more details on class diagrams$ or information on the other eight diagrams$ refer to

The Unified Modeling Language User Guide "! Grad! Booch$ =ames 1um"augh$ and

#var =aco"son

* > *