Class Diagram
Class Diagram
Class Diagram
Overview
Defineobjectmodelingandexplain itsbenefits. Recognizeandunderstandthebasicconceptsandconstructs ofobjectmodeling. diagrams DefinetheUMLanditsvarioustypesofdiagrams. Evolveabusinessrequirementsusecasemodelintoasystem analysisusecasemodel. Discoverobjectsandclasses,andtheirrelationships. Constructaclassdiagram.
IntroductiontoObjectModeling
Object j orientedanalysis y ( (OOA) ) anapproach pp usedto
studyexistingobjects toseeiftheycanbereusedor adaptedfornewuses definenewormodifiedobjects thatwillbecombined withexistingobjectsintoausefulbusinesscomputing application
IntroductiontotheUML
UnifiedModelingLanguage(UML) asetof modelingconventionsthatisusedtospecify ordescribeasoftwaresystemintermsof objects.
TheUMLdoesnotprescribeamethodfor developingsystemsonlyanotationthatisnow widely yaccepted p asastandardforobject j modeling.
UMLDiagrams
UseCaseModelDiagrams StaticStructureDiagrams
Classdiagrams Objectdiagrams
InteractionDiagrams
Sequencediagrams Collaborationdiagrams g
StateDiagrams
Statechartdiagrams Activitydiagrams
ImplementationDiagrams
Componentdiagrams Deploymentdiagrams
CSE 307 Presentation 8 5
ClassDiagram:ClassvsInstance
Class name compartment Attributes compartment Operations Ope at o s co compartment pa t e t
Class
CSE 307 Presentation 8 6
ClassDiagram:ClassvsInstance
Object name compartment Attribute values Instances do not have operations
Instance
CSE 307 Presentation 8 7
ClassDiagram:ClassvsInstance
ObjectInstancesoftenchangesfrequently whileclassesaregenerallypermanent. Instancescanbedestroyed destroyed. Objectinstancescanbeupdated.
ClassDiagram:Attributes
Attributesare: Partoftheessentialdescriptionofaclass The h commonstructureof fwhat h the h class l can know Eachobjecthasitsownvalue foreach attributeinitsclass
ClassDiagram:LinkvsAssociation
Yellow Partridge:Client
Carlos Moncada:StaffMember
Links
CSE 307 Presentation 8 10
ClassDiagram:LinkvsAssociation
Association role
StaffMember staffName staffNo staffStartDate staffContact liaises with companyAddress companyEmail companyFax p y companyName companyTelephone
Association
Client
Association name
ClassDiagram:LinkvsAssosiation
Anassociationdescribessetofsimilar instances. Linkedinstancesmaybeofdifferentclassor fromthesameclass. Link Li kcanconnectinstances i oitself. i lf
12
ClassDiagram:Multiplicity
Associationshavemultiplicity Multiplicityistherangeofpermitted cardinalitiesofanassociation Represententerprise (orbusiness) rules Forexample:
Anybankcustomermayhaveoneormore accou s accounts Everyaccountisforone,andonlyone,customer
13
ClassDiagram:Multiplicity
Multiplicities
StaffMember staffName staffNo staffStartDate 1 liaises with Client companyAddress Add 0..* companyEmail p y companyFax companyName companyTelephone
Exactly one staff member liaises with each client A staff member may liaise with zero, one or more clients
CSE 307 Presentation 8 14
ClassDiagram:MultiplicityNotations
Multiplicity Exactly one Z Zero or one Zero or more One or more p Range g Specific Notations 1 blank 0 1 0..1 0..* 0 * * 1 * 1.. 0..3 Example A student studies in exactly one department Ab bed d may h have zero or one patient Student may issue for zero or more IC A course may have one or more teachers A student may y borrow at most 3 books from the library
15
ClassDiagram:Operations
Operationsare: Anessentialpartofthedescriptionofaclass The h commonb behaviour h i shared h d b byall llobjects bj oftheclass Servicesthatobjectsofaclasscanprovideto otherobjects
16
ClassDiagram:Operations
Operationsdescribe whatinstancesofa classcando:
Setorrevealattribute values Performcalculations Sendmessagesto otherobjects Createordestroylinks
Campaign actualCost campaignFinishDate campaignStartDate p g completionDate datePaid estimatedCost titl title checkCampaignBudget ( ) getCampaignContribution ( ) recordPayment ( ) setCompleted ( )
17
ClassDiagram:State
Stateofaninstanceisdefinedby
Thevaluesoftheattributes Thenumberoflinks
ClassDiagram:Stereotypes
WhatdoesStereotype Stereotype mean?
Ref3:Section7.3.2(page165).
ClassDiagram:Stereotypes
BoundaryClasses
Modelsinteractionbetweenthesystemand actors Mayincludeinterfacestoothersoftwareor devices Maintaskistomanagethetransferofinformation acrosssystem y boundaries
20
Notationsforboundaryclass
<<boundary>> User Interface::AddAdvertUI startInterface( ) assignStaff( g () selectClient( ) selectCampaign( ) User Interface::AddAdvertUI
User Interface::AddAdvertUI
CSE 307 Presentation 8 21
ClassDiagram:Stereotypes
EntityClasses
Modelsinformationandtheirrelatedbehavior Maybeaboutaperson person,areallifeobjectoran event Oftenrequirepersistentstorage
22
Notationsforentityclass
<<entity>> Campaign title campaignStartDate campaignFinishDate getCampaignAdverts( ) addNewAdvert( () Campaign title campaignStartDate campaignFinishDate getCampaignAdverts( ) addNewAdvert( )
Campaign
CSE 307 Presentation 8 23
ClassDiagram:Stereotypes
ControlClasses
Modelthecoordination,sequencing,transactions andcontrolofotherobjects Oneusecaseshouldresultinonecontrolclass
24
Notationsforcontrolclass
<<control>> Control::AddAdvert showClientCampaigns( ) showCampaignAdverts( ) createNewAdvert( ) C t l AddAd Control::AddAdvert t
AddAvert
CSE 307 Presentation 8 25
ClassDiagram:Stereotypes
Use-case pay fee Use-case register RegisterUI
ShowPRUI
ShowResultUI
RegistrationFee StudentInfo St d tI f
FineInfo
CSE 307 Presentation 8
C CourseInfo I f
R lt Result
26
BuildingtheClassDiagram
Twomainwaystoproducethis:
Directlybasedonknowledgeoftheapplication domain(aDomainModel) Byproducingaseparateclassdiagramforeach usecase,thenassemblingthemintoasingle model(anAnalysisClassModel)
27
FromUseCasetoClasses
Startwithoneusecase Identifythelikelyclassesinvolved(theuse casecollaboration) Drawacollaborationdiagramthatfulfilsthe needsoftheusecase Translatethiscollaborationintoaclass diagram Repeatforotherusecases Combinethediagrams
CSE 307 Presentation 8 28
FromUseCasetoClasses:Step1
Use Case : Assign staff to a campaign Actor Action 1. None 3. Select the client name 5. Select the relevant campaign 7. Select a staff member to assign to the campaign
CSE 307 Presentation 8
System Response 2. Display List of Client Name 4. List the titles of the campaigns related to that client 6. Display list of staff not assigned i d to t that th t campaign i 8. Present a message confirming the allocation of staff
29
FromUseCasetoClasses:Step2
Guidelinetoeliminatecandidateclasses Anumberoftestshelptocheckwhethera candidateclassisreasonable
Isitbeyondthescopeofthesystem? Does D i itrefer f tothe h systemasawhole? h l ? Doesitduplicateanotherclass? Isittoovague? (Moreonnextslide)
CSE 307 Presentation 8 30
FromUseCasetoClasses:Step2
Isittootiedupwithphysicalinputsandoutputs? Isitreallyanattribute? Isitreallyanoperation? Isitreallyanassociation?
31
FromUseCasetoClasses:Step2
Theidentifiedclasses
Client Campaign StaffMember
32
FromUseCasetoClasses:Step3
Initialcollaborationdiagram
Campaign Manager
:Client
:Campaign
:StaffMember
33
FromUseCasetoClasses:Step3
Addingboundaryandcontrolclasses
Campaign Manager
:AssignStaffUI
:AssignStaff
5 3 4
:Client Cli t
CSE 307 Presentation 8
:Campaign C i
:StaffMember St ffM b
34
FromUseCasetoClasses:Step3
Addingmessages
1 2
Campaign Manager
:AssignStaffUI
:AssignStaff
7: AssignStaff()
:Client Cli t
CSE 307 Presentation 8
:Campaign C i
:StaffMember St ffM b
35
FromUseCasetoClasses:Step3
Finalizing
4: selectClient() 7: selectCampaign() 10: assignStaff() 5: showClientCampaign() 8: showCampaignStaff() 11: asssignStaff() 2: startInterface() ()
Campaign Manager
:AssignStaffUI
:AssignStaff
13: AssignStaff()
:Client Cli t
CSE 307 Presentation 8
:Campaign C i
:StaffMember St ffM b
36
FromUseCasetoClasses:Step4
<<boundary>> <<b d >> AssignStaffUI startInterface() assignStaff() selectClient() selectCampaign() p g () <<control>> << t l>> AssignStaff assignStaff() getClientCampaign() showCampaignStaff()
AssigningOperations:CRCCards
ClassResponsibilityCollaboration Class Responsibility Collaborationcardshelp tomodelinteractionbetweenobjects Foragivenscenario(orusecase):
Brainstormtheobjects Allocate All toteammembers b Roleplaytheinteraction
38
CRCCards
Class Name: Responsibilities Responsibilities of a class are listed in this section. Collaborations Collaborations C ll b i with i h other h classes are listed here, together with a brief description of the purpose of the collaboration.
39
Class Name R Responsibilities ibiliti Provide client information. Provide list of campaigns. Class Name Responsibilities
Client C ll b ti Collaborations
Provide campaign information. Provide list of adverts. adverts Add a new advert. Class Name Responsibilities Provide advert details. Construct adverts. Advert
Collaborations
40
CRCCards
Effectiveroleplaydependsonanexplicit strategyfordistributingresponsibilityamong classes Forexample:
Each E hrole l player l t tries i t tob bel lazy Persuadesotherplayerstheir classshouldaccept responsibilityforagiventask
42