Class Diagram Notation

Embed Size (px)

Citation preview

  • 7/27/2019 Class Diagram Notation

    1/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 rst section. It is generally a NOUNor short nounphrase to represent the concept. The rst letter of every ord in the class name, e.g.

    Television Set.

    Attributes are listed in the second section ! generally a NOUNto describe the property ordata held in a class. The rst letter of every ord in the attribute name is upper case, e"ceptthe very rst letter hich is loer case, e.g. screen Si#e.

    The third section contains the operation of the class ! generally a VERBor short verb phrasehich describes the behaviour. The rst letter of every ord is upper case, e"cept the very

    rst 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 neob%ects, destructorshich delete an ob%ect and those hich &uery or manipulate attributevalues get and set accessors. These standard operations are not usually displayed ondiagrams.

    Attributes

    1

    Class name Television

    switch On()switch Off()change Channel()setVolume()setBrightness()set Screensize()

    volumechannel

    brightnessscreen Size

    Attributes

    Methods

    Attributes

    Methods

    Television

    volume!ntegerchannel"numbrightness #screenSizeAnum

    switchOn()switchOff()changeChannel(channel"numsetVolume(volumeinteger)setBrightne$$(bright#)

    setScreenSize(size"num)

  • 7/27/2019 Class Diagram Notation

    2/8

    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 boxesshould contain specifc valuesfor the attributes.

    +perations can have ! a set of parameters 'in brac$ets(each parameter can optionally have a data typea return type 'preceded by a colon(

    Visibility

    +peration and Attribute names can also be preceded by a visibility indicator of public '(,private '!( or protected'-(.

    ublicattributes and operations can be accessed freely by any ob%ect of the class.

    Attributesare usually privateor protecte!to ensure encapsulationof the data.

    rivate attributesand operations are for use by the instanceitself.

    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 dene the properties and responsibilities of a general concept. Theterms instance and ob%ect are generally synonymous and are often interchanged.

    +b%ects or instances all contain the attributes and implement the operations dened by their

    class, therefore +b%ects do not include operations.

    2

    Television

    !volumeInteger!channel*num!brightness /!screenSi#eAnum

    sitch+n'(sitch+0'(changeChannel'channel*numset1olume'volumeinteger(set2rightne""'bright/(

  • 7/27/2019 Class Diagram Notation

    3/8

    Object

    Object

    Associations an! lin&sTo or$ together, +b%ects need to have relationships. 3elationships beteen classes arecalled 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"istbeteen classes5 they ill be lin$ed on a Class 4iagram.

    'uanti#ying Associations

    *ach end of an association lin$ can be &uantied by specifying multiplicity. This is shon as aminimum and ma"imum number of instances separated by to dots. Specic numbers canbe used or an asteris$ 6 can denote an unlimited number.

    #ero or 7 8..7+ne or many 8..6+ne or more 7..6An e"act number e.g. 9, :, 97A range of numbers 7..;

    Examples

    7 7

    7 6

    7 7..6

    7 9, 22C7brightness / > ;=screenSi#eAnum > ?ide

    MyKitchen:Television

    volumeInteger > 22C9brightness / > @8screenSi#eAnum > ?ide

    country capital

    course student

    package cd

    car door

    plces

  • 7/27/2019 Class Diagram Notation

    4/8

    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 andis shon as a hollo diamond at the hole end of the association line.

    cd Data Model

    Tree

    Trunk Root BranchLeaf

    % %&&' %&&' %&&'

    ,eneralisation an! -pecialisation

    Classes can be organised hierarchically into Super!classes and Subclasses ! here one ob%ectis a kind ofanother 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"eritanceInheritance 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 ! hencespecialisation.

    4

  • 7/27/2019 Class Diagram Notation

    5/8

    cd Logical Model

    Fish

    Swim() void

    Puffer Fish

    uff() void

    Buil!ing an Object /o!el

    7 4etermine relevant classes9 Identify relationships Identify attributes

    < Identify +perations

    -tep 0

    Identify Classes D generally a E+UE or SF+3T E+UE GF3AS* to represent aconcept.

    Identify 3edundant Classes D 9 or more classes hich identify the same $ind ofob%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 RelationshipsD these may be straight associations beteen classes or mayinclude aggregation (part o#+ and generalisation (&in! o#+ structures. Gerusing theproblem for verbphrases can produce a list of potential associations.

    -tep 2 .!enti#y Attributes

    -tep 3 .!enti#y Operations +perations can be identied at this stage but are mainlyidentied 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 allshareholders re&uire season tic$ets, an application must be submitted. Applications shouldindicate seat preference. Shareholder applications must indicate shareholding hilesupporters 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 ofseats hich are all purchased together. or ordinary seats there is a choice of bloc$ hile forboth types there is a choice of stand. The registration system ill inform the club system ofbilling and delivery re&uirements for successful applications.

    -tep 0 Identify Classes

    5

  • 7/27/2019 Class Diagram Notation

    6/8

    A #ootball club desires a registration system to allocate seats to season tic&etapplicants. Applications are received from s"are"ol!ers, supporters clubs andor!inary supporters. -"are"ol!ershave priorityand receive a !iscounton the cost o#tic&ets. Since not all s"are"ol!ers re&uire season tic&ets, an application must besubmitted. Applications should indicate seat pre#erence. -"are"ol!er applicationsmust indicate s"are"ol!inghile supporters4 club4s applicationsill indicate numbero# seats re5uire!and list o# members. There are to types o# tic&et for boxesand foror!inary seats. A boxcontains a number of seatshich are all purchased together. or

    or!inary seatsthere 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! !eliveryre5uirementsfor success#ul applications.

    ootballClub 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 StandChoiceClubSystem 2illingAnd4elivery3e&uir

    ementSuccessfulApplication

    Re!un!ant Classes

    ootballClubJClubSystem 3egistrationSystem Seat

    SeasonTic$etApplicantJSeasonTic$etJApplication

    ShareholderJShareholderApplication

    SupportersClubJSupportersClubApplication

    +rdinarySupporter Griority 4iscount

    Tic$etCost SeatGreference Shareholding3e&uiredEumber+fSeats Member)ist Tic$etTypeJType

    2o" +rdinarySeat 2loc$Choice

    StandChoice 2illingAnd4elivery3e&uirement

    SuccessfulApplication

    Attributes4iscount, Tic$etCost, SeatGreference, Sharholding, 3e&uiredEumber+fSeats, Member)ist,

    Tic$etType, 2loc$Choice, StandChoice, 2illingAnd4elivery3e&uirement, SuccessfulApplication

    ootballClub 3egistrationSystem Seat

    Application ShareholderApplication SupportersClubApplication

    +rdinarySupporter Griority 2o"

    +rdinarySeat

    Vague ClassesGriority, +rdinarySupporter

    ootballClubJClubSystem

    3egistrationSystem Seat Application

    Shareholder SupportersClub 2o" +rdinarySeat

    This gives us a list of candidate classes for consideration. It is &uite possible that these maybe re%ected, added to or amended during the development, e.g. the candidate class

    6

  • 7/27/2019 Class Diagram Notation

    7/8

    ootballClub ill probably prove to be outside the scope of the system ith billing anddelivery re&uirements implemented ith this in mind.

    -tep 1 Identify relationshipsA football club desires a registration system to allocateseats 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 allshareholders requireseason tic$ets, an application must be submitted. Applications should

    indicate seat preference. Shareholder applications must indicate shareholding hilesupportersH clubHs applications ill indicatenumber of seats re&uired and list of members.There areto types of tic$et for bo"es and for ordinary seats. A bo" containsa number ofseats hich are allpurchasedtogether. or ordinary seats there isa choice of bloc$ hile forboth types there is a choice of stand. The registration system ill inform the club system ofbilling and delivery re&uirements for successful applicants. This allos us to dra an initialclass diagram

    cd

    RegistrationSyste Foot!allClu!

    "##lication Seat

    Shareholder"##lication Su##ortersClu!"##licationBo$ %rdinarySeat

    -tep 2 Identify Attributes

    7

  • 7/27/2019 Class Diagram Notation

    8/8

    cd

    RegistrationSyste Foot!allClu!

    "##lication

    * name char

    * address char

    * seatreference char

    Seat

    * cost double

    * stand int

    Shareholder"##lication

    * shareholding int

    Su##ortersClu!"##lication

    * club+ame char

    * member,ist char

    * re-uired+oSeats int

    Bo$

    * noSeats int

    %rdinarySeat

    * bloc. int

    8