Sunteți pe pagina 1din 8

Class Diagram Notation

A Class is represented by a rectangle, optionally divided into a number of sections.


The name of the class MUST appear in the frst section. It is generally a NOUN or short noun
phrase to represent the concept. The frst letter of every ord in the class name, e.g.
Television Set.
Attributes are listed in the second section ! generally a NOUN to describe the property or
data held in a class. The frst letter of every ord in the attribute name is upper case, e"cept
the very frst letter hich is loer case, e.g. screen Si#e.
The third section contains the operation of the class ! generally a VERB or short verb phrase
hich describes the behaviour. The frst letter of every ord is upper case, e"cept the very
frst letter hich is loer case, e.g. change Channel.
In order to $eep draings compact, the second and third sections are not alays shon.
Most classes have a standard set of operations, including constructors hich create ne
ob%ects, destructors hich delete an ob%ect and those hich &uery or manipulate attribute
values get and set accessors. These standard operations are not usually displayed on
diagrams.
Attributes
1
Class name
Television
switch On()
switch Off()
change Channel()
setVolume()
setBrightness()
set Screensize()
volume
channel
brightness
screen Size
Attributes
Methods
Attributes
Methods
Television
volume!nteger
channel"num
brightness #
screenSizeAnum
switchOn()
switchOff()
changeChannel(channel"num
setVolume(volumeinteger)
setBrightne$$(bright#)
setScreenSize(size"num)
Attributes can have ! a data type 'preceded by a colon(
a default value 'preceded by an e&uals sign(
Attributes are listed for C)ASS*S ith type and default value.
Object boxes should contain specifc values for the attributes.
+perations can have ! a set of parameters 'in brac$ets(
each parameter can optionally have a data type
a return type 'preceded by a colon(
Visibility
+peration and Attribute names can also be preceded by a visibility indicator of public ',(,
private '!( or protected'-(.
ublic attributes and operations can be accessed freely by any ob%ect of the class.
Attributes are usually private or protecte! to ensure encapsulation of the data.
rivate attributes and operations are for use by the instance itself.
rotecte! attributes and operations can be accessed by the instance itself or by
any in"erite! instance.
Classes or Objects
Classes provi!e a template #or many potential object instances$
Objects "ol! specifc values$
Operations are liste! in Class boxes NO% Object boxes$
The concept of class is to defne the properties and responsibilities of a general concept. The
terms instance and ob%ect are generally synonymous and are often interchanged.
+b%ects or instances all contain the attributes and implement the operations defned by their
class, therefore +b%ects do not include operations.
2
Television
!volume.Integer
!channel.*num
!brightness. /
!screenSi#e.Anum
,sitch+n'(
,sitch+0'(
,changeChannel'channel.*
num
,set1olume'volume.integer(
,set2rightne""'bright./(
,setScreenSi#e'si#e.*num(
Object
Object
Associations an! lin&s
To or$ together, +b%ects need to have relationships. 3elationships beteen classes are
called associations.
If an association e"ists beteen classes, they ill be lin$ed on a Class 4iagram.

An association is dran as a line beteen to classes. More than one association can e"ist
beteen classes5 they ill be lin$ed on a Class 4iagram.
'uanti#ying Associations
*ach end of an association lin$ can be &uantifed by specifying multiplicity. This is shon as a
minimum and ma"imum number of instances separated by to dots. Specifc numbers can
be used or an asteris$ 6 can denote an unlimited number.
#ero or 7 8..7
+ne or many 8..6
+ne or more 7..6
An e"act number e.g. 9, :, 97
A range of numbers 7..;
Examples
7 7
7 6
7 7..6
7 9,<,=
3
customer order
MyLounge:Television
volume.Integer > <
channel.*num > 22C7
brightness. / > ;=
screenSi#e.Anum > ?ide
MyKitchen:Television
volume.Integer > <
channel.*num > 22C9
brightness. / > @8
screenSi#e.Anum > ?ide
country capital
course student
package cd
car door
plces
Aggregation ()"ole * art+
+ne particular association is hen one ob%ect consists of a number of smaller, simpler ob%ects
! the smaller ob%ect is part of the larger object. This relationship is called Aggregation and
is shon as a hollo diamond at the AholeA end of the association line.
cd Data Model
Tree
Trunk Root Branch Leaf
% %&&' %&&' %&&'
,eneralisation an! -pecialisation
Classes can be organised hierarchically into Super!classes and Subclasses ! here one ob%ect
is a kind of another ob%ect. This relationship is called Beneralisation.
cd Fish
Fish
Shark Cod Tuna
It is shon as a hollo triangle pointing from the Subclasses to the Super!class.
.n"eritance
Inheritance means that all subclasses assume the attributes and operations of the super!
class. Therefore the sub!class only model details hich are special to them ! hence
specialisation.
4
cd Logical Model
Fish
( Swi m() voi d
Puffer Fish
( )uff() voi d
Buil!ing an Object /o!el
7 4etermine relevant classes
9 Identify relationships
C Identify attributes
< Identify +perations
-tep 0
Identify Classes D generally a E+UE or SF+3T E+UE GF3AS* to represent a
concept.
Identify 3edundant Classes D 9 or more classes hich identify the same $ind of
ob%ect
3emove attributes D features of classes e.g. name, address etc.
3emove 1ague Classes D imprecise classes
Groduce Candidate Classes for consideration
-tep 1 Identify Relationships D these may be straight associations beteen classes or may
include aggregation (part o#+ and generalisation (&in! o#+ structures. Gerusing the
problem for verb phrases can produce a list of potential associations.
-tep 2 .!enti#y Attributes
-tep 3 .!enti#y Operations +perations can be identifed at this stage but are mainly
identifed during class design. The basic operations of constructing and destructing ob%ects,
setting values, accessing values, displaying values and operators should be considered
Example 1
A football club desires a registration system to allocate seats to season tic$et applicants.
Applications are received from shareholders, supporters clubs and ordinary supporters.
Shareholders have priority and receive a discount on the cost of tic$ets. Since not all
shareholders re&uire season tic$ets, an application must be submitted. Applications should
indicate seat preference. Shareholder applications must indicate shareholding hile
supporters clubsH applications ill indicate number of seats re&uired and list of members.
There are to types of tic$et. for bo"es and for ordinary seats. A bo" contains a number of
seats hich are all purchased together. Ior ordinary seats there is a choice of bloc$ hile for
both types there is a choice of stand. The registration system ill inform the club system of
billing and delivery re&uirements for successful applications.
-tep 0 Identify Classes
5
A #ootball club desires a registration system to allocate seats to season tic&et
applicants. Applications are received from s"are"ol!ers, supporters clubs and
or!inary supporters. -"are"ol!ers have priority and receive a !iscount on the cost o#
tic&ets. Since not all s"are"ol!ers re&uire season tic&ets, an application must be
submitted. Applications should indicate seat pre#erence. -"are"ol!er applications
must indicate s"are"ol!ing hile supporters4 club4s applications ill indicate number
o# seats re5uire! and list o# members. There are to types o# tic&et. for boxes and for
or!inary seats. A box contains a number of seats hich are all purchased together. Ior
or!inary seats there is a c"oice o# bloc& hile for both types there is a c"oice o# stan!.
The registration system ill inform the club system of billing an! !elivery
re5uirements for success#ul applications.
IootballClub 3egistrationSystem Seat
SeasonTic$etApplicant Application Shareholder
SupportersClub +rdinarySupporter Griority
4iscount Tic$etCost SeasonTic$et
SeatGreference ShareholderApplication Shareholding
SupportsClubApplication 3e&uiredEumber+fSeats Member)ist
Tic$etType 2o" +rdinarySeat
2loc$Choice Type StandChoice
ClubSystem 2illingAnd4elivery3e&uir
ement
SuccessfulApplication
Re!un!ant Classes
IootballClubJClubSystem 3egistrationSystem Seat
SeasonTic$etApplicantJ
SeasonTic$etJApplication
ShareholderJ
ShareholderApplication
SupportersClubJ
SupportersClubApplicatio
n
+rdinarySupporter Griority 4iscount
Tic$etCost SeatGreference Shareholding
3e&uiredEumber+fSeats Member)ist Tic$etTypeJType
2o" +rdinarySeat 2loc$Choice
StandChoice 2illingAnd4elivery3e&uir
ement
SuccessfulApplication
Attributes
4iscount, Tic$etCost, SeatGreference, Sharholding, 3e&uiredEumber+fSeats, Member)ist,
Tic$etType, 2loc$Choice, StandChoice, 2illingAnd4elivery3e&uirement, SuccessfulApplication
IootballClub 3egistrationSystem Seat
Application ShareholderApplication SupportersClubApplicati
on
+rdinarySupporter Griority 2o"
+rdinarySeat
Vague Classes
Griority, +rdinarySupporter
IootballClubJClubSyste
m
3egistrationSystem Seat Application
Shareholder SupportersClub 2o" +rdinarySeat
This gives us a list of candidate classes for consideration. It is &uite possible that these may
be re%ected, added to or amended during the development, e.g. the candidate class
6
IootballClub ill probably prove to be outside the scope of the system ith billing and
delivery re&uirements implemented ith this in mind.
-tep 1 Identify relationships
A football club desires a registration system to allocate seats to season tic$et applicants.
Applications are received from shareholders, supporters clubs and ordinary supporters.
Shareholders have priority and receive a discount on the cost of tic$ets. Since not all
shareholders require season tic$ets, an application must be submitted. Applications should
indicate seat preference. Shareholder applications must indicate shareholding hile
supportersH clubHs applications ill indicate number of seats re&uired and list of members.
There are to types of tic$et. for bo"es and for ordinary seats. A bo" contains a number of
seats hich are all purchased together. Ior ordinary seats there is a choice of bloc$ hile for
both types there is a choice of stand. The registration system ill inform the club system of
billing and delivery re&uirements for successful applicants. This allos us to dra an initial
class diagram.
cd
RegistrationSyste Foot!allClu!
"##lication Seat
Shareholder"##lication
Su##ortersClu!"##lication
Bo$ %rdinarySeat
-tep 2 Identify Attributes
7
cd
RegistrationSyste Foot!allClu!
"##lication
* name char
* address char
* seat)reference char
Seat
* cost doubl e
* stand i nt
Shareholder"##lication
* sharehol di ng i nt
Su##ortersClu!"##lication
* cl ub+ame char
* member,i st char
* re-ui red+oSeats i nt
Bo$
* noSeats i nt
%rdinarySeat
* bl oc. i nt
8

S-ar putea să vă placă și