UML Class Diagram Tutorial - Visual Paradigm

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

A Comprehensive UML Class Diagram tutorial written for everyone who want to learn ... Implementation: describes how classes will implement their interfaces. Home Support Current:UMLClassDiagramTutorial UMLClassDiagramTutorial UMLClassDiagramTutorial WhatisaClass UMLClassNotation PerspectivesofClassDiagram Relationshipsbetweenclasses ClassDiagramExample:OrderSystem ClassDiagramExample:GUI RelatedLinks TheUMLClassdiagramisagraphicalnotationusedtoconstructandvisualizeobjectorientedsystems.AclassdiagramintheUnifiedModelingLanguage(UML)isatypeofstaticstructurediagramthatdescribesthestructureofasystembyshowingthesystem's: classes, theirattributes, operations(ormethods), andtherelationshipsamongobjects. LearnUMLFaster,BetterandEasier AreyoulookingforaFreeUMLtoolforlearningUMLfaster,easierandquicker?VisualParadigmCommunityEditionisaUMLsoftwarethatsupportsallUMLdiagramtypes.Itisaninternationalaward-winningUMLmodeler,andyetitiseasy-to-use,intuitive&completelyfree. FreeDownload WhatisaClass? AClassisablueprintforanobject.Objectsandclassesgohandinhand.Wecan'ttalkaboutonewithouttalkingabouttheother.AndtheentirepointofObject-OrientedDesignisnotaboutobjects,it'saboutclasses,becauseweuseclassestocreateobjects.Soaclassdescribeswhatanobjectwillbe,butitisn'ttheobjectitself. Infact,classesdescribethetypeofobjects,whileobjectsareusableinstancesofclasses.EachObjectwasbuiltfromthesamesetofblueprintsandthereforecontainsthesamecomponents(propertiesandmethods).Thestandardmeaningisthatanobjectisaninstanceofaclassandobject-Objectshavestatesandbehaviors. Example Adoghasstates-color,name,breedaswellasbehaviors-wagging,barking,eating.Anobjectisaninstanceofaclass. UMLClassNotation Aclassrepresentaconceptwhichencapsulatesstate(attributes)andbehavior(operations).Eachattributehasatype.Eachoperationhasasignature.Theclassnameistheonlymandatoryinformation. ClassName: Thenameoftheclassappearsinthefirstpartition. ClassAttributes: Attributesareshowninthesecondpartition. Theattributetypeisshownafterthecolon. Attributesmapontomembervariables(datamembers)incode. ClassOperations(Methods): Operationsareshowninthethirdpartition.Theyareservicestheclassprovides. Thereturntypeofamethodisshownafterthecolonattheendofthemethodsignature. Thereturntypeofmethodparametersareshownafterthecolonfollowingtheparametername.Operationsmapontoclassmethodsincode ClassVisibility The+,-and#symbolsbeforeanattributeandoperationnameinaclassdenotethevisibilityoftheattributeandoperation. +denotespublicattributesoroperations -denotesprivateattributesoroperations #denotesprotectedattributesoroperations ParameterDirectionality Eachparameterinanoperation(method)maybedenotedasin,outorinoutwhichspecifiesitsdirectionwithrespecttothecaller.Thisdirectionalityisshownbeforetheparametername. PerspectivesofClassDiagram Thechoiceofperspectivedependsonhowfaralongyouareinthedevelopmentprocess.Duringtheformulationofadomainmodel,forexample,youwouldseldommovepasttheconceptualperspective.Analysismodelswilltypicallyfeatureamixofconceptualandspecificationperspectives.Designmodeldevelopmentwilltypicallystartwithheavyemphasisonthespecificationperspective,andevolveintotheimplementationperspective. Adiagramcanbeinterpretedfromvariousperspectives: Conceptual:representstheconceptsinthedomain Specification:focusisontheinterfacesofAbstractDataType(ADTs)inthesoftware Implementation:describeshowclasseswillimplementtheirinterfaces Theperspectiveaffectstheamountofdetailtobesuppliedandthekindsofrelationshipsworthpresenting.Aswementionedabove,theclassnameistheonlymandatoryinformation. Relationshipsbetweenclasses UMLisnotjustaboutprettypictures.Ifusedcorrectly,UMLpreciselyconveyshowcodeshouldbeimplementedfromdiagrams.Ifpreciselyinterpreted,theimplementedcodewillcorrectlyreflecttheintentofthedesigner.CanyoudescribewhateachoftherelationshipsmeanrelativetoyourtargetprogramminglanguageshownintheFigurebelow? Ifyoucan'tyetrecognizethem,noproblemthissectionismeanttohelpyoutounderstandUMLclassrelationships.Aclassmaybeinvolvedinoneormorerelationshipswithotherclasses.Arelationshipcanbeoneofthefollowingtypes: Inheritance(orGeneralization): Ageneralizationisataxonomicrelationshipbetweenamoregeneralclassifierandamorespecificclassifier.Eachinstanceofthespecificclassifierisalsoanindirectinstanceofthegeneralclassifier.Thus,thespecificclassifierinheritsthefeaturesofthemoregeneralclassifier. Representsan"is-a"relationship. Anabstractclassnameisshowninitalics. SubClass1andSubClass2arespecializationsofSuperClass. Thefigurebelowshowsanexampleofinheritancehierarchy.SubClass1andSubClass2arederivedfromSuperClass.Therelationshipisdisplayedasasolidlinewithahollowarrowheadthatpointsfromthechildelementtotheparentelement. InheritanceExample-Shapes Thefigurebelowshowsaninheritanceexamplewithtwostyles.Althoughtheconnectorsaredrawndifferently,theyaresemanticallyequivalent. Association AssociationsarerelationshipsbetweenclassesinaUMLClassDiagram.Theyarerepresentedbyasolidlinebetweenclasses.Associationsaretypicallynamedusingaverborverbphrasewhichreflectstherealworldproblemdomain. SimpleAssociation Astructurallinkbetweentwopeerclasses. ThereisanassociationbetweenClass1andClass2 Thefigurebelowshowsanexampleofsimpleassociation.Thereisanassociationthatconnectsthe<>classClass1and<>classClass2.Therelationshipisdisplayedasasolidlineconnectingthetwoclasses. Cardinality Cardinalityisexpressedintermsof: onetoone onetomany manytomany Aggregation Aspecialtypeofassociation. Itrepresentsa"partof"relationship. Class2ispartofClass1. Manyinstances(denotedbythe*)ofClass2canbeassociatedwithClass1. ObjectsofClass1andClass2haveseparatelifetimes. Thefigurebelowshowsanexampleofaggregation.Therelationshipisdisplayedasasolidlinewithaunfilleddiamondattheassociationend,whichisconnectedtotheclassthatrepresentstheaggregate. Composition Aspecialtypeofaggregationwherepartsaredestroyedwhenthewholeisdestroyed. ObjectsofClass2liveanddiewithClass1. Class2cannotstandbyitself. Thefigurebelowshowsanexampleofcomposition.Therelationshipisdisplayedasasolidlinewithafilleddiamondattheassociationend,whichisconnectedtotheclassthatrepresentsthewholeorcomposite. Dependency Anobjectofoneclassmightuseanobjectofanotherclassinthecodeofamethod.Iftheobjectisnotstoredinanyfield,thenthisismodeledasadependencyrelationship. Aspecialtypeofassociation. Existsbetweentwoclassesifchangestothedefinitionofonemaycausechangestotheother(butnottheotherwayaround). Class1dependsonClass2 Thefigurebelowshowsanexampleofdependency.Therelationshipisdisplayedasadashedlinewithanopenarrow. Thefigurebelowshowsanotherexampleofdependency.ThePersonclassmighthaveahasReadmethodwithaBookparameterthatreturnstrueifthepersonhasreadthebook(perhapsbycheckingsomedatabase). Realization Realizationisarelationshipbetweentheblueprintclassandtheobjectcontainingitsrespectiveimplementationleveldetails.Thisobjectissaidtorealizetheblueprintclass.Inotherwords,youcanunderstandthisastherelationshipbetweentheinterfaceandtheimplementingclass. Forexample,theOwnerinterfacemightspecifymethodsforacquiringpropertyanddisposingofproperty.ThePersonandCorporationclassesneedtoimplementthesemethods,possiblyinverydifferentways. ClassDiagramExample:OrderSystem ClassDiagramExample:GUI Aclassdiagrammayalsohavenotesattachedtoclassesorrelationships. TrytoDrawUMLClassDiagramNow You'velearnedwhataClassDiagramisandhowtodrawaClassDiagram.It'stimetodrawaClassDiagramofyourown.GetVisualParadigmCommunityEdition,afreeUMLsoftware,andcreateyourownClassDiagramwiththefreeClassDiagramtool.It'seasy-to-useandintuitive. FreeDownload RelatedLinks WhatisUnifiedModelingLanguage? ProfessionalUMLtool Turneverysoftwareprojectintoasuccessfulone. TryVisualParadigmFree Weusecookiestoofferyouabetterexperience.Byvisitingourwebsite,youagreetotheuseofcookiesasdescribedinourCookiePolicy. OK



請為這篇文章評分?