UML 2 Tutorial - Class Diagram - Sparx Systems

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

The class diagram shows the building blocks of any object-orientated system. Class diagrams depict a static view of the model, or part of the model, describing ...     Products EnterpriseArchitect Whatisnewinv16.0 Whatwasnewinv15.2 Whatwasnewinv15.1 Whatwasnewinv15 Overview Professional Corporate Unified Ultimate CompareEditions FreeTrial RegisteredDownloads AdditionalInfo 30MinuteTour ReleaseHistory LicenseInfo FloatingLicenses AcademicPricing SystemRequirements EULA MDGExtensions 3rdPartyExtensions ProCloudServer Whatisnewinv5.0Whatwasnewinv4.2Whatwasnewinv4.1Whatwasnewinv4 Overview WebEA Integrations FloatingLicenseServer CompareEditions FreeTrial Downloads AdditionalInfo 30MinuteTour ReleaseHistory SystemRequirements EULA Prolaborate Whatisnewin4.2 Overview Introduction Resources Articles Documentation ReleaseNotes FAQ Events Videos FreeTrial Downloads AdditionalInfo RequestaDemo ProofofConcept ProlaborateSaaS EULA SystemRequirements Pricing EnterpriseArchitect ProCloudServer Prolaborate Support Forum UserGuide/Help ContactUs BugReport RequestaFeature ChangeYourEmail PriorityBugReport EmailSupport EmailSales FAQ Support Sales CompanyDetails NewsRoom Resellers Africa Asia Europe MiddleEast NorthAmerica Oceania SouthAmerica SparxServices NorthAmerica Australia CentralEurope MiddleEast UnitedKingdom SistersCompanies Argentina China CentralEurope MiddleEast India Japan Trainers/Consultants Africa NorthAmerica SouthAmerica Asia Europe Oceania MiddleEast Online Resources Video&Webinars DemoVideos UpcomingWebinars WebinarsLibrary SignUp PDFLibrary Fundamentals Modeling Collaboration Publishing Simulation ProjectManagement ViewEntireLibrary Other Whitepapers Tutorials CaseStudies LearningCenter DiagramGallery Brochures RegisteredUsers EnterpriseArchitect ProCloudServer AllUsers FreeDownloads DBMSRepositoryScripts UserSecurityKey AllResources> UMLTutorial Community DownloadNow EnterpriseArchitect  ProCloudServer  Prolaborate  Login Resources Tutorials UML2Tutorial ClassDiagram UML2Tutorial-ClassDiagram ClassDiagrams Theclassdiagramshowsthebuildingblocksofanyobject-orientatedsystem.Classdiagramsdepictastaticviewofthemodel,orpartofthemodel,describingwhatattributesandbehaviorithasratherthandetailingthemethodsforachievingoperations.Classdiagramsaremostusefulinillustratingrelationshipsbetweenclassesandinterfaces.Generalizations,aggregations,andassociationsareallvaluableinreflectinginheritance,compositionorusage,andconnectionsrespectively. Thediagrambelowillustratesaggregationrelationshipsbetweenclasses.Thelighteraggregationindicatesthattheclass"Account"usesAddressBook,butdoesnotnecessarilycontainaninstanceofit.Thestrong,compositeaggregationsbytheotherconnectorsindicateownershiporcontainmentofthesourceclassesbythetargetclasses,forexampleContactandContactGroupvalueswillbecontainedinAddressBook. Classes Aclassisanelementthatdefinestheattributesandbehaviorsthatanobjectisabletogenerate.Thebehaviorisdescribedbythepossiblemessagestheclassisabletounderstand,alongwithoperationsthatareappropriateforeachmessage.Classesmayalsohavedefinitionsofconstraints,taggedvaluesandstereotypes. ClassNotation Classesarerepresentedbyrectangleswhichshowthenameoftheclassandoptionallythenameoftheoperationsandattributes.Compartmentsareusedtodividetheclassname,attributesandoperations. Inthediagrambelowtheclasscontainstheclassnameinthetopmostcompartment,thenextcompartmentdetailstheattributes,withthe"center"attributeshowinginitialvalues.ThefinalcompartmentshowstheoperationssetWidth,setLengthandsetPositionandtheirparameters.Thenotationthatprecedestheattribute,oroperationname,indicatesthevisibilityoftheelement:ifthe+symbolisused,theattribute,oroperation,hasapubliclevelofvisibility;ifa-symbolisused,theattribute,oroperation,isprivate.Inadditionthe#symbolallowsanoperation,orattribute,tobedefinedasprotected,whilethe~symbolindicatespackagevisibility. Interfaces Aninterfaceisaspecificationofbehaviorthatimplementersagreetomeet;itisacontract.Byrealizinganinterface,classesareguaranteedtosupportarequiredbehavior,whichallowsthesystemtotreatnon-relatedelementsinthesameway–thatis,throughthecommoninterface. Interfacesmaybedrawninasimilarstyletoaclass,withoperationsspecified,asshownbelow.Theymayalsobedrawnasacirclewithnoexplicitoperationsdetailed.Whendrawnasacircle,realizationlinkstothecircleformofnotationaredrawnwithouttargetarrows. Tables AlthoughnotapartofthebaseUML,atableisanexampleofwhatcanbedonewithstereotypes.Itisdrawnwithasmalltableiconintheupperrightcorner.Tableattributesarestereotyped«column».Mosttableswillhaveaprimarykey,beingoneormorefieldsthatformauniquecombinationusedtoaccessthetable,plusaprimarykeyoperationwhichisstereotyped«PK».Sometableswillhaveoneormoreforeignkeys,beingoneormorefieldsthattogethermapontoaprimarykeyinarelatedtable,plusaforeignkeyoperationwhichisstereotyped«FK». Associations Anassociationimpliestwomodelelementshavearelationship-usuallyimplementedasaninstancevariableinoneclass.Thisconnectormayincludenamedrolesateachend,cardinality,directionandconstraints.Associationisthegeneralrelationshiptypebetweenelements.Formorethantwoelements,adiamondrepresentationtoolboxelementcanbeusedaswell.Whencodeisgeneratedforclassdiagrams,namedassociationendsbecomeinstancevariablesinthetargetclass.So,fortheexamplebelow,"playsFor"willbecomeaninstancevariableinthe"Player"class. Generalizations Ageneralizationisusedtoindicateinheritance.Drawnfromthespecificclassifiertoageneralclassifier,thegeneralizeimplicationisthatthesourceinheritsthetarget'scharacteristics.Thefollowingdiagramshowsaparentclassgeneralizingachildclass.Implicitly,aninstantiatedobjectoftheCircleclasswillhaveattributesx_position,y_positionandradiusandamethoddisplay().Notethattheclass"Shape"isabstract,shownbythenamebeingitalicized. Thefollowingdiagramshowsanequivalentviewofthesameinformation. Aggregations Aggregationsareusedtodepictelementswhicharemadeupofsmallercomponents.Aggregationrelationshipsareshownbyawhitediamond-shapedarrowheadpointingtowardsthetargetorparentclass. Astrongerformofaggregation-acompositeaggregation-isshownbyablackdiamond-shapedarrowheadandisusedwherecomponentscanbeincludedinamaximumofonecompositionatatime.Iftheparentofacompositeaggregationisdeleted,usuallyallofitspartsaredeletedwithit;howeverapartcanbeindividuallyremovedfromacompositionwithouthavingtodeletetheentirecomposition.Compositionsaretransitive,asymmetricrelationshipsandcanberecursive. Thefollowingdiagramillustratesthedifferencebetweenweakandstrongaggregations.Anaddressbookismadeupofamultiplicityofcontactsandcontactgroups.Acontactgroupisavirtualgroupingofcontacts;acontactmaybeincludedinmorethanonecontactgroup.Ifyoudeleteanaddressbook,allthecontactsandcontactgroupswillbedeletedtoo;ifyoudeleteacontactgroup,nocontactswillbedeleted. AssociationClasses Anassociationclassisaconstructthatallowsanassociationconnectiontohaveoperationsandattributes.Thefollowingexampleshowsthatthereismoretoallocatinganemployeetoaprojectthanmakingasimpleassociationlinkbetweenthetwoclasses:theroletheemployeetakesupontheprojectisacomplexentityinitsownrightandcontainsdetailthatdoesnotbelongintheemployeeorprojectclass.Forexample,anemployeemaybeworkingonseveralprojectsatthesametimeandhavedifferentjobtitlesandsecuritylevelsoneach. Dependencies Adependencyisusedtomodelawiderangeofdependentrelationshipsbetweenmodelelements.Itwouldnormallybeusedearlyinthedesignprocesswhereitisknownthatthereissomekindoflinkbetweentwoelements,butitistooearlytoknowexactlywhattherelationshipis.Laterinthedesignprocess,dependencieswillbestereotyped(stereotypesavailableinclude«instantiate»,«trace»,«import»,andothers),orreplacedwithamorespecifictypeofconnector. Traces Thetracerelationshipisaspecializationofadependency,linkingmodelelementsorsetsofelementsthatrepresentthesameideaacrossmodels.Tracesareoftenusedtotrackrequirementsandmodelchanges.Aschangescanoccurinbothdirections,theorderofthisdependencyisusuallyignored.Therelationship'spropertiescanspecifythetracemapping,butthetraceisusuallybi-directional,informalandrarelycomputable. Realizations Thesourceobjectimplementsorrealizesthedestination.Realizationsareusedtoexpresstraceabilityandcompletenessinthemodel-abusinessprocessorrequirementisrealizedbyoneormoreusecases,whichareinturnrealizedbysomeclasses,whichinturnarerealizedbyacomponent,etc.Mappingrequirements,classes,etc.acrossthedesignofyoursystem,upthroughthelevelsofmodelingabstraction,ensuresthebigpictureofyoursystemremembersandreflectsallthelittlepicturesanddetailsthatconstrainanddefineit.Arealizationisshownasadashedlinewithasolidarrowhead. Nestings Anestingisconnectorthatshowsthesourceelementisnestedwithinthetargetelement.Thefollowingdiagramshowsthedefinitionofaninnerclass,althoughinEAitismoreusualtoshowthembytheirpositionintheprojectviewhierarchy. Products Products EnterpriseArchitect ProCloudServer Prolaborate UMLataGlance UMLataGlance UMLTools PHPUMLModeling BusinessProcessModeling ModelDrivenArchitecture RequirementsManagement SoftwareDevelopment Solutions Solutions Corporate Government Small/MediumEnterprise ITProfessionals Trainers Academic Resources Resources UML2.0Tutorial CorporateResources DeveloperResources MediaResources Support Support OnlineManual UserForum ReportaBug FeatureRequest CompareEditions SystemRequirements GlobalPartners GlobalPartners Trainers Resellers SisterCompanies TechnicalPartners StandardsOrganizations ©2000-2022   SparxSystemsPtyLtd.   AllrightsReserved. Legal Privacy Aboutus



請為這篇文章評分?