UML Class Diagram Tutorial - Visual Paradigm
文章推薦指數: 80 %
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<
延伸文章資訊
- 1UML Class Diagrams
Realization: A class implements an interface. For example, the Owner interface might specify meth...
- 2Implements relationships in domain modeling class diagrams
In domain modeling class diagrams, an implements relationship exists between two classes when one...
- 3UML Class Diagram Tutorial - Visual Paradigm
A Comprehensive UML Class Diagram tutorial written for everyone who want to learn ... Implementat...
- 4Implement the application specification - UML Designer
From the existing application UML definition, Bob defines the application at a lower level. ... D...
- 5UML 2 Class Diagram Guidelines - Agile Modeling
Interfaces are implemented, "realized" in UML parlance, by classes and components - to realize an...