Class Diagram Relationships in UML Explained with Examples

文章推薦指數: 80 %
投票人數:10人

refers to a type of relationship wherein one associated class is a child of another by virtue of assuming the same functionalities of the parent ... CreatelyBlogDiagrams Updatedon:8September2022 Classdiagramsarethemainbuildingblocksofobject-orientedmodelingsoitisimportantthatyouunderstandthevariousclassdiagramrelationshipsandhowtheyaffectyoursolution.Wehavelistedthembelowwithexamples. Createlysimplifiescreatingclassdiagramsbyshowingthelogicalrelationshipbasedoncontext. Createaclassdiagram>> ClassDiagramRelationships Classesareinterrelatedtoeachotherinspecificways.Inparticular,relationshipsinclassdiagramsincludedifferenttypesoflogicalconnections.ThefollowingaresuchtypesoflogicalconnectionsthatarepossibleinUML: AssociationDirectedAssociationReflexiveAssociationMultiplicityAggregationCompositionInheritance/GeneralizationRealization RelationshipsinUMLclassdiagrams Association Association isabroadtermthatencompassesjustaboutanylogicalconnectionorrelationshipbetweenclasses.Forexample,passengersandairlinemaybelinkedasabove. DirectedAssociation DirectedAssociation referstoadirectionalrelationshiprepresentedbyalinewithanarrowhead.Thearrowheaddepictsacontainer-containeddirectionalflow. ReflexiveAssociation ReflexiveAssociation Thisoccurswhenaclassmayhavemultiplefunctionsorresponsibilities.Forexample,astaffmemberworkinginanairportmaybeapilot,aviationengineer,ticketdispatcher,guard,ormaintenancecrewmember.Ifthemaintenancecrewmemberismanagedbytheaviationengineertherecouldbeamanagedbyrelationshipintwoinstancesofthesameclass. Multiplicity Multiplicity istheactivelogicalassociationwhenthecardinalityofaclassinrelationtoanotherisbeingdepicted.Forexample,onefleetmayincludemultipleairplanes,whileonecommercialairplanemaycontainzerotomanypassengers.Thenotation0..*inthediagrammeans“zerotomany”. Aggregation Aggregation referstotheformationofaparticularclassasaresultofoneclassbeingaggregatedorbuiltasacollection.Forexample,theclass“library”ismadeupofoneormorebooks,amongothermaterials.Inaggregation,thecontainedclassesarenotstronglydependentonthelifecycleofthecontainer.Inthesameexample,bookswillremainsoevenwhenthelibraryisdissolved.Toshowaggregationinadiagram,drawalinefromtheparentclasstothechildclasswithadiamondshapeneartheparentclass. Toshowaggregationinadiagram,drawalinefromtheparentclasstothechildclasswithadiamondshapeneartheparentclass. Composition Composition Thecompositionrelationshipisverysimilartotheaggregationrelationship.withtheonlydifferencebeingitskeypurposeofemphasizingthedependenceofthecontainedclasstothelifecycleofthecontainerclass.Thatis,thecontainedclasswillbeobliteratedwhenthecontainerclassisdestroyed.Forexample,ashoulderbag’ssidepocketwillalsoceasetoexistoncetheshoulderbagisdestroyed. ToshowacompositionrelationshipinaUMLdiagram,useadirectionallineconnectingthetwoclasses,withafilleddiamondshapeadjacenttothecontainerclassandthedirectionalarrowtothecontainedclass. Inheritance/Generalization Inheritance referstoatypeofrelationshipwhereinoneassociatedclassisachildofanotherbyvirtueofassumingthesamefunctionalitiesoftheparentclass.Inotherwords,thechildclassisaspecifictypeoftheparentclass.ToshowinheritanceinaUMLdiagram,asolidlinefromthechildclasstotheparentclassisdrawnusinganunfilledarrowhead. Realization Realization denotestheimplementationofthefunctionalitydefinedinoneclassbyanotherclass.ToshowtherelationshipinUML,abrokenlinewithanunfilledsolidarrowheadisdrawnfromtheclassthatdefinesthefunctionalityoftheclassthatimplementsthefunction.Intheexample,theprintingpreferencesthataresetusingtheprintersetupinterfacearebeingimplementedbytheprinter. Drawing classdiagramsusingCreately We’vegivenalotofthoughttorelationshipswhenwebuiltourclassdiagrammingtools.Ourconnectorsadjusttothecontextandshowonlythemostlogicalrelationshipswhenconnectingclasses.Thissignificantlyreducedyourchancesofmakingamistake. Createaclassdiagram>> Drawingfromscratchcanbecumbersome.Youcangetstartedimmediatelyusingourprofessionallydesignedclassdiagrams.Browseourclassdiagramexamples andpicktheonethat’scloselyrelatedtoyoursystem. WhataretheClassDiagrams? Classdiagramsarethemainbuildingblockinobject-orientedmodeling.Theyareusedtoshowthedifferentobjectsinasystem, theirattributes,theiroperations, andtherelationshipsamongthem. Thefollowingfigureisanexampleofasimpleclass: Simpleclassdiagramwithattributesandoperations Intheexample,aclasscalled“loanaccount”isdepicted.Classesinclassdiagramsarerepresentedbyboxesthatarepartitionedintothree: Thetoppartitioncontainsthenameoftheclass.Themiddlepartcontainstheclass’sattributes.Thebottompartitionshowsthepossibleoperationsthatareassociatedwiththeclass. Theexampleshowshowaclasscanencapsulatealltherelevantdataofaparticularobjectinaverysystematicandclearway.Aclassdiagramisacollectionofclassessimilartotheoneabove. AnyMoreQuestionsAboutClassDiagramRelationships? IhopeI’veclearlyexplainedthevariousrelationshipsbetweenclassdiagrams.Theyarenotascomplexasyouthinkandcanbemasteredwithsomepractice.Andbyusingourtoolyoushouldn’thaveanytroublecomingupwithclassdiagrams.Ifyouhaveanymorequestionsdon’thesitatetoaskinthecommentssection.Also,checkoutthisguidetoUMLDiagramTypeswithExamplesforfurtherreading. References: 1. UMLbasics:TheclassdiagramAnintroductiontostructurediagramsinUML2byDonaldBell 2.ClassdiagramaspublishedontheWikipediawebsite 3. TheUMLClassDiagramPart1aspublishedonthewebsitedeveloper.com 4.TheClassDiagramfromVisualCaseTool–UMLTutorialaspublishedonVisualCasewebsite 5. AssociationsaspublishedontheSybasewebsite JoinoverthousandsoforganizationsthatuseCreatelytobrainstorm,plan,analyze,andexecutetheirprojectssuccessfully.Getstartedhere aggregationassociationclassdiagramrelationshipsclassdiagramsinheritancerealizationUML MoreRelatedArticles UnderstandingUMLClassDiagramRelationships 75NewTemplatesforMindmaps,Flowcharts,UMLdiagramsandmore PART2:WhattypeofUMLdiagramshouldyoubeusing? ABasicintrotoUseCaseDiagrams Comments KiraboIbrahim Thankyousomuchforthishelpfulinformation,itreallyclearedmyconfusionIhadaboutumlclassdiagrams 14.03.2021 - reply Virendrasamundrasingh HowcanIfindtheclassinaproject?ImeantosayhowIcanfindhowmanyclassinaproject? Isthereanytechnique? 07.03.2019 - reply kaushik Itshouldbelikethis–”abrokenlinewithanunfilledsolidarrowheadisdrawnfromtheclassthatdefinesthefunctionality“to”theclassthatimplementsthefunction.” 04.03.2019 - reply BrajeshSoni ForInheritance/Generalization:bankaccount,logicallyseemstobeparentclasstofixedaccount.Sounfilledarrowheadhastobeendatbankaccountbox. 04.07.2018 - reply Saqib GoodExplanation. 09.02.2018 - reply Aditya Isnttherealizationlinedirectionotherwayround? abrokenlinewithanunfilledsolidarrowheadisdrawntotheclassthatdefinesthefunctionalityfromtheclassthatimplementsthefunction 24.07.2017 - reply Goteguru Thediagrammightbecorrect.Theexplanationshouldbesomethinglikethis:theprintersetupimplementsthegenericprinterfunctionality. 05.12.2017 - reply Xavi Theproblemiswhathaswrittendowntheauthor.Hesays“Intheexample,theprintingpreferencesthataresetusingtheprintersetupinterfacearebeingimplementedbytheprinter.”soit’stheoppositeofwhatyouaresaying. 06.11.2018 - reply mahadev Whatdoes1..4meaninassociation 20.09.2016 - reply Priya Itmeansthatminimumonevalueandmaximumof4. 13.09.2017 - reply cate Amazingcontenthere,itisverymuchhelpful.Thankyouforsharing. 22.06.2016 - reply Regha ItwasofgreathelpNishadha!tnkusomch!🙂 24.08.2015 - reply indhumathi explanationisgoodandwhenugivewithexampleitwillbeeasyforbeginners……… 17.02.2015 - reply shereeff Thanksyousomuch 31.12.2014 - reply MananaDero thkssomuch.igottounderstandclassdiagramsthelayman’sway.bigup 01.08.2014 - reply Mohsen verygoodbut,youcansummarizeyourwordsinfewwords 02.07.2014 - reply yousuf incompositiondiagramabove,doyouthinkthebookswouldn’tsurvivethelibrary-death??.AmorefittingexamplewouldbehumanandlegORbulbandfilamentORcurrentandvoltage,etc. 02.04.2014 - reply aya canyoutellmemoreexampleswithexplanations 31.03.2014 - reply Jimmie Interestingtheconceptofaggregationandcomposition.Gotfewinsightsmoretoenrichmypointofviewframe. ThanksfirsharingNishadha,haveaniceday. Jim 26.02.2014 - reply Blazyprince onDirectedassociation,howdoesplanerbethecontainedofpassenger(container)Ithinkitiswrongifnotexplaintomeplease!!! 23.01.2014 - reply DarrenBruce Goodsummary,justonething,youhavethewrongexampleinComposition.YoushouldLibraryandBooksagain(asperAggregation)andthentalkaboutShoulderBagandShoulderBagPocketinthetext.Basicallyyouneedtorelabelthediagramexample.Cheers 25.09.2013 - reply accountingsoftware Largenumberofindividualslooksforthesedetailsbuttheywillnotgeteffectiveone.Itrulyseveralthanksfordiscussingit 03.09.2013 - reply Thashreef WhatistheRelationshipbetweenEmployeeandEmployee_DependentClass 22.08.2013 - reply mcr1234 veryuseful,thankyouverymuch^^ 20.08.2013 - reply priyansh howdoishowprimarykeyinclassdiagram???? 13.08.2013 - reply Prashanth Theexampleyou’vegivenforinheritance/generalizationshouldbetheotherwayround.BankAccountshouldbetheParent.Fixed,Savingsaccountsshouldbethechildren.Bankaccountwillholdthegeneralattributes/methodswhereastheFixedaccountwillhavespecificattributes/methodsinheritingtherestfromtheBankaccount. 24.06.2013 - reply Tony Yesyouareright…itsspecifiedwrongly 08.09.2016 - reply SaadMalik Outofcuriosity,intheAirplanetoPassengersMultiplicityexample,shouldn’tthisrelationshipbeaAggregation?Ingeneral,couldyoupleasegiveanexampleofwhenanassociationismoreaptthananaggregation/compositionwithmultipleobjects? 30.05.2013 - reply UzmaPathan Hi,Ihaveaquery.CanrealizationrelationshipexistbetweenaPackageandanInterface?Canwedrawarealizationrelation(Emptyheadarrow)betweenaPackageandanInterfaceinUML? 07.05.2013 - reply AkashAgrawal nicepointswhichuhavecleartome….canuhaveexplainclassdiagramofonlineexamination…. 12.04.2013 - reply Nishadha HiSatish, MaybeyoucanreferourERdiagramtutorialtohelpwithyourproject. 15.03.2013 - reply satish heyhiicanyouhelpusoutinmakingerdiagramforourproject… 14.03.2013 - reply AbhasTandon Thanksalot..Iwaslittleconfusedaboutsimpleanddirectedassociationsbutyourpostclearedmydoubt. 12.02.2013 - reply Nishadha HiAgecoat, Thanksforvisitingandleavingacomment.Ithinktheexampleisvalidbutabetterjobcouldbedonebyaddinganexample.Ihaveaddedanexampletomakeitmoreclear. 07.01.2013 - reply aliy thankforyoureffortineedsomehelpintermsofthisdiagramamastudentatkampalaugandaihaveascenariobutiwantcomealongwithclassdiagram,statechart,usecasediagramandcollaborationwithsequencediagramineedyourassistance, 1 CASESTUDY MentalHealthCarePatientManagementSystem (MHCPMS) Thiscasestudyisbasedonarealsystemthatisinuseinanumberofhospitals. Forreasonsofcommercialconfidentiality,Ihavechangedthenameofthe systemandhavenotincludedinformationaboutanyspecificsystemfeatures. 1.Background Aregionalhealthauthoritywishestoprocureaninformationsystemtohelp managethecareofpatientssufferingfrommentalhealthproblems.Theoverall goalsofthesystemaretwofold: 1.Togeneratemanagementinformationthatallowshealthservicemanagersto assessperformanceagainstlocalandgovernmenttargets. 2.Toprovidemedicalstaffwithtimelyinformationtofacilitatethetreatment ofpatients. Thehealthauthorityhasanumberofclinicsthatpatientsmayattendin differenthospitalsandinlocalhealthcentres.Patientsneednotalwaysattend thesameclinicandsomeclinicsmaysupport‘dropin’aswellaspre-arranged appointments. Thenatureofmentalhealthproblemsissuchthatpatientsareoften disorganisedsomaymissappointments,deliberatelyoraccidentallylose prescriptionsandmedication,forgetinstructionsandmakeunreasonable demandsonmedicalstaff.Inaminorityofcases,theymaybeadangerto themselvesortootherpeople.Theymayregularlychangeaddressandmaybe homelessonalong-termorshort-termbasis.Wherepatientsaredangerous, theymayneedtobe‘sectioned’–confinedtoasecurehospitalfortreatment andobservation. Usersofthesystemincludeclinicalstaff(doctors,nurses,healthvisitors), receptionistswhomakeappointmentsandmedicalrecordsstaff.Reportsare generatedforhospitalmanagementbymedicalrecordsstaff.Managementhave nodirectaccesstothesystem. Thesystemisaffectedbytwopiecesoflegislation(intheUK,Actsof Parliament).ThesearetheDataProtectionActthatgovernstheconfidentiality MHCPMSCaseStudy2 ofpersonalinformationandtheMentalHealthActthatgovernsthecompulsory detentionofpatientsdeemedtobeadangertothemselvesorothers. ThesystemisNOTacompletemedicalrecordssystemwhereallinformation aboutapatients’medicaltreatmentismaintained.Itissolelyintendedto supportmentalhealthcaresoifapatientissufferingfromsomeotherunrelated condition(suchashighbloodpressure)thiswouldnotbeformallyrecordedin thesystem. 24.05.2014 - reply adeyeni mailmeletsdiscuss,imalsodoinanhospitalmanagementsystem 17.06.2014 - reply Agecoat Yourexplanationofthereflexiveassociationstrikesmeasodd. Yourexplationofreflexivedepictsanassociationclassbetween‘airport’and‘staff’inwhichtheassociationdepictsthe‘multipleroles’oftheparticular‘staff’inregardtothe‘airport’. Thereflexiveassociation,tome,depictsthesituationofarelationbetweenequallytypedinstances,forexample,likeinameshnetworkorina(genealogical)parent–childconstructionoftypePerson. Alsoconsideraddingtheassociationclassasaconceptualclassrelationshipconstruct. 05.01.2013 - reply amal niceefforttohelppeople…iappreciate🙂 31.10.2012 - reply sid HiNishadha,yourexplanationwasveryinformative,canyousendmetheclassmodellinddiagramforbillsplittingapplications 25.09.2012 - reply Nishadha HiRajasekhar, YoucanbrowsethroughourUMLclassdiagramsexamplesandfindagoodonethatmatchesyourneeds. 13.09.2012 - reply RajasekharReddy HiNishada,yourexplanationisverycleartounderstand,canyousendmetheclassmodellingexampleofhospitalitymanagementsystem. 12.09.2012 - reply WimalPerera HiNishi,itsagreatblogman.Ijustaccidentlycameacrossthiswhenbrowsingweb. Greatwork!!Keepitup. 10.05.2012 - reply AmithPerera WimalufromJoes2003? 04.05.2016 - reply irajosolli thanku verynice………….. 10.05.2012 - reply Nishadha Hinoway, You’recorrect.Wehavecorrectedthemistakenow.Thanksfortakingthetimetopointthatout. 24.04.2012 - reply noway aggregationancompositioninaclassdiagrammareshownbythediamondontheaggregatecalssside.Itmeansthe“Library”calsswillhavethediamondandnotthe“Books”.Verycommonmistake,mostifthebeginnersmake. thanksnoway 24.04.2012 - reply LeaveacommentCancelreply Yourmessage*Yourname* Youremail* Pleaseenterananswerindigits:eleven−five= Δ Backtotop



請為這篇文章評分?