Class diagram - Wikipedia
文章推薦指數: 80 %
In software engineering, a class diagram in the Unified Modeling Language (UML) is a type of static structure diagram that describes the structure of a ... Classdiagram FromWikipedia,thefreeencyclopedia Jumptonavigation Jumptosearch Typeofstaticstructurediagram Thisarticleneedsadditionalcitationsforverification.Pleasehelpimprovethisarticlebyaddingcitationstoreliablesources.Unsourcedmaterialmaybechallengedandremoved.Findsources: "Classdiagram" – news ·newspapers ·books ·scholar ·JSTOR(February2009)(Learnhowandwhentoremovethistemplatemessage)UMLdiagramtypes StructuralUMLdiagrams Classdiagram Componentdiagram Compositestructurediagram Deploymentdiagram Objectdiagram Packagediagram Profilediagram BehavioralUMLdiagrams Activitydiagram Communicationdiagram Interactionoverviewdiagram Sequencediagram Statediagram Timingdiagram Usecasediagram vte HierarchyofUML2.5Diagrams,shownasaclassdiagram.Theindividualclassesarerepresentedjustwithonecompartment,buttheyoftencontainuptothreecompartments.Insoftwareengineering,aclassdiagramintheUnifiedModelingLanguage(UML)isatypeofstaticstructurediagramthatdescribesthestructureofasystembyshowingthesystem'sclasses,theirattributes,operations(ormethods),andtherelationshipsamongobjects. Theclassdiagramisthemainbuildingblockofobject-orientedmodeling.Itisusedforgeneralconceptualmodelingofthestructureoftheapplication,andfordetailedmodeling,translatingthemodelsintoprogrammingcode.Classdiagramscanalsobeusedfordatamodeling.[1]Theclassesinaclassdiagramrepresentboththemainelements,interactionsintheapplication,andtheclassestobeprogrammed. Inthediagram,classesarerepresentedwithboxesthatcontainthreecompartments: Thetopcompartmentcontainsthenameoftheclass.Itisprintedinboldandcentered,andthefirstletteriscapitalized. Themiddlecompartmentcontainstheattributesoftheclass.Theyareleft-alignedandthefirstletterislowercase. Thebottomcompartmentcontainstheoperationstheclasscanexecute.Theyarealsoleft-alignedandthefirstletterislowercase. Aclasswiththreecompartments.Inthedesignofasystem,anumberofclassesareidentifiedandgroupedtogetherinaclassdiagramthathelpstodeterminethestaticrelationsbetweenthem.Indetailedmodeling,theclassesoftheconceptualdesignareoftensplitintosubclasses. Inordertofurtherdescribethebehaviorofsystems,theseclassdiagramscanbecomplementedbyastatediagramorUMLstatemachine.[2] Contents 1Members 1.1Visibility 1.2Scope 2Relationships 2.1Instance-levelrelationships 2.1.1Dependency 2.1.2Association 2.1.3Aggregation 2.1.4Composition 2.1.5DifferencesbetweenCompositionandAggregation 2.2Class-levelrelationships 2.2.1Generalization/Inheritance 2.2.2Realization/Implementation 2.3Generalrelationship 2.3.1Dependency 2.4Multiplicity 3Analysisstereotypes 3.1Entities 4Seealso 5References 6Externallinks Members[edit] UMLprovidesmechanismstorepresentclassmembers,suchasattributesandmethods,andadditionalinformationaboutthemlikeconstructors. Visibility[edit] Tospecifythevisibilityofaclassmember(i.e.anyattributeormethod),thesenotationsmustbeplacedbeforethemembers'name:[3] + Public - Private # Protected ~ Package Aderivedpropertyisapropertywhosevalue(orvalues)isproducedorcomputedfromotherinformation,forexample,byusingvaluesofotherproperties. Aderivedpropertyisshownwithitsnameprecededbyaforwardslash'/'.[4] Scope[edit] TheUMLspecifiestwotypesofscopeformembers:instanceandclass,andthelatterisrepresentedbyunderlinednames.[5] Instancemembersarescopedtoaspecificinstance. Attributevaluesmayvarybetweeninstances Methodinvocationmayaffecttheinstance’sstate(i.e.changeinstance’sattributes) Classmembersarecommonlyrecognizedas“static”inmanyprogramminglanguages.Thescopeistheclassitself. Attributevaluesareequalforallinstances Methodinvocationdoesnotaffecttheclassifier’sstate Toindicateaclassifierscopeforamember,itsnamemustbeunderlined.Otherwise,instancescopeisassumedbydefault. Relationships[edit] UMLrelationsnotation Arelationshipisageneraltermcoveringthespecifictypesoflogicalconnectionsfoundonclassandobjectdiagrams.UMLdefinesthefollowingrelationships: Instance-levelrelationships[edit] Dependency[edit] Adependencyisatypeofassociationwherethereisasemanticconnectionbetweendependentandindependentmodelelements.[6]Itexistsbetweentwoelementsifchangestothedefinitionofoneelement(theserverortarget)maycausechangestotheother(theclientorsource).Thisassociationisuni-directional.Adependencyisdisplayedasadashedlinewithanopenarrowthatpointsfromtheclienttothesupplier. Association[edit] Classdiagramexampleofassociationbetweentwoclasses Anassociationrepresentsafamilyoflinks.Abinaryassociation(withtwoends)isnormallyrepresentedasaline.Anassociationcanlinkanynumberofclasses.Anassociationwiththreelinksiscalledaternaryassociation.Anassociationcanbenamed,andtheendsofanassociationcanbeadornedwithrolenames,ownershipindicators,multiplicity,visibility,andotherproperties.Therearefourdifferenttypesofassociation:bi-directional,uni-directional,aggregation(includescompositionaggregation)andreflexive.Bi-directionalanduni-directionalassociationsarethemostcommonones.Forinstance,aflightclassisassociatedwithaplaneclassbi-directionally.Associationrepresentsthestaticrelationshipsharedamongtheobjectsoftwoclasses. Aggregation[edit] ClassdiagramshowingAggregationbetweentwoclasses.Here,aProfessor'hasa'classtoteach. Aggregationisavariantofthe"hasa"associationrelationship;aggregationismorespecificthanassociation.Itisanassociationthatrepresentsapart-wholeorpart-ofrelationship.Asshownintheimage,aProfessor'hasa'classtoteach.Asatypeofassociation,anaggregationcanbenamedandhavethesameadornmentsthatanassociationcan.However,anaggregationmaynotinvolvemorethantwoclasses;itmustbeabinaryassociation.Furthermore,thereishardlyadifferencebetweenaggregationsandassociationsduringimplementation,andthediagrammayskipaggregationrelationsaltogether.[7] Aggregationcanoccurwhenaclassisacollectionorcontainerofotherclasses,butthecontainedclassesdonothaveastronglifecycledependencyonthecontainer.Thecontentsofthecontainerstillexistwhenthecontainerisdestroyed. InUML,itisgraphicallyrepresentedasahollowdiamondshapeonthecontainingclasswithasinglelinethatconnectsittothecontainedclass.Theaggregateissemanticallyanextendedobjectthatistreatedasaunitinmanyoperations,althoughphysicallyitismadeofseverallesserobjects. Composition[edit] Twoclassdiagrams.ThediagramontopshowsCompositionbetweentwoclasses:ACarhasexactlyoneCarburetor,andaCarburetorisapartofoneCar.Carburetorscannotexistasseparateparts,detachedfromaspecificcar.ThediagramonbottomshowsAggregationbetweentwoclasses:APondhaszeroormoreDucks,andaDuckhasatmostonePond(atatime).DuckcanexistseparatelyfromaPond,e.g.itcanlivenearalake.WhenwedestroyaPondweusuallydonotkillalltheDucks. TheUMLrepresentationofacompositionrelationshipshowscompositionasafilleddiamondshapeonthecontainingclassendofthelinesthatconnectcontainedclass(es)tothecontainingclass. DifferencesbetweenCompositionandAggregation[edit] Compositionrelationship 1.Whenattemptingtorepresentreal-worldwhole-partrelationships,e.g.anengineisapartofacar. 2.Whenthecontainerisdestroyed,thecontentsarealsodestroyed,e.g.auniversityanditsdepartments. Aggregationrelationship 1.Whenrepresentingasoftwareordatabaserelationship,e.g.carmodelengineENG01ispartofacarmodelCM01,astheengine,ENG01,maybealsopartofadifferentcarmodel.[8] 2.Whenthecontainerisdestroyed,thecontentsareusuallynotdestroyed,e.g.aprofessorhasstudents;whentheprofessordiesthestudentsdonotdiealongwithhim. Thustheaggregationrelationshipisoften"catalog"containmenttodistinguishitfromcomposition's"physical"containment. Class-levelrelationships[edit] Generalization/Inheritance[edit] ClassdiagramshowinggeneralizationbetweenthesuperclassPersonandthetwosubclassesStudentandProfessor Itindicatesthatoneofthetworelatedclasses(thesubclass)isconsideredtobeaspecializedformoftheother(thesupertype)andthesuperclassisconsideredaGeneralizationofthesubclass.Inpractice,thismeansthatanyinstanceofthesubtypeisalsoaninstanceofthesuperclass.Anexemplarytreeofgeneralizationsofthisformisfoundinbiologicalclassification:humansareasubclassofsimian,whichisasubclassofmammal,andsoon.Therelationshipismosteasilyunderstoodbythephrase'anAisaB'(ahumanisamammal,amammalisananimal). TheUMLgraphicalrepresentationofaGeneralizationisahollowtriangleshapeonthesuperclassendoftheline(ortreeoflines)thatconnectsittooneormoresubtypes. symbolicofrealization(subclass)_______▻(superclass) Thegeneralizationrelationshipisalsoknownastheinheritanceor"isa"relationship. Thesuperclass(baseclass)inthegeneralizationrelationshipisalsoknownasthe"parent",superclass,baseclass,orbasetype. Thesubtypeinthespecializationrelationshipisalsoknownasthe"child",subclass,derivedclass,derivedtype,inheritingclass,orinheritingtype. Notethatthisrelationshipbearsnoresemblancetothebiologicalparent–childrelationship:theuseofthesetermsisextremelycommon,butcanbemisleading. AisatypeofB Forexample,"anoakisatypeoftree","anautomobileisatypeofvehicle" Generalizationcanonlybeshownonclassdiagramsandonusecasediagrams. Realization/Implementation[edit] InUMLmodelling,arealizationrelationshipisarelationshipbetweentwomodelelements,inwhichonemodelelement(theclient)realizes(implementsorexecutes)thebehaviorthattheothermodelelement(thesupplier)specifies. TheUMLgraphicalrepresentationofaRealizationisahollowtriangleshapeontheinterfaceendofthedashedline(ortreeoflines)thatconnectsittooneormoreimplementers.Aplainarrowheadisusedontheinterfaceendofthedashedlinethatconnectsittoitsusers.Incomponentdiagrams,theball-and-socketgraphicconventionisused(implementorsexposeaballorlollipop,whereasusersshowasocket). Realizationscanonlybeshownonclassorcomponentdiagrams. Arealizationisarelationshipbetweenclasses,interfaces,componentsandpackagesthatconnectsaclientelementwithasupplierelement.Arealizationrelationshipbetweenclasses/componentsandinterfacesshowsthattheclass/componentrealizestheoperationsofferedbytheinterface. symbolicofrealization(implementer)-------▻(interface) Generalrelationship[edit] Classdiagramshowingdependencybetween"Car"classand"Wheel"class(Anevenclearerexamplewouldbe"CardependsonWheel",becauseCaralreadyaggregates(andnotjustuses)Wheel) Dependency[edit] Dependencycanbeaweakerformofbondthatindicatesthatoneclassdependsonanotherbecauseitusesitatsomepointintime. Oneclassdependsonanotheriftheindependentclassisaparametervariableorlocalvariableofamethodofthedependentclass.Sometimestherelationshipbetweentwoclassesisveryweak.Theyarenotimplementedwith membervariablesatall.Rathertheymightbeimplementedasmemberfunctionarguments. Multiplicity[edit] Thisassociationrelationshipindicatesthat(atleast)oneofthetworelatedclassesmakereferencetotheother.Thisrelationshipisusuallydescribedas"AhasaB"(amothercathaskittens,kittenshaveamothercat). TheUMLrepresentationofanassociationisalineconnectingthetwoassociatedclasses.Ateachendofthelinethereisoptionalnotation.Forexample,wecanindicate,usinganarrowheadthatthepointyendisvisiblefromthearrowtail.Wecanindicateownershipbytheplacementofaball,theroletheelementsofthatendplaybysupplyinganamefortherole,andthemultiplicityofinstancesofthatentity(therangeofnumberofobjectsthatparticipateintheassociationfromtheperspectiveoftheotherend). 0 Noinstances(rare) 0..1 Noinstances,oroneinstance 1 Exactlyoneinstance 1..1 Exactlyoneinstance 0..* Zeroormoreinstances * Zeroormoreinstances 1..* Oneormoreinstances Analysisstereotypes[edit] Entities[edit] Entityclassesmodellong-livedinformationhandledbythesystem,andsometimesthebehaviorassociatedwiththeinformation.Theyshouldnotbeidentifiedasdatabasetablesorotherdata-stores. Theyaredrawnascircleswithashortlineattachedtothebottomofthecircle.Alternatively,theycanbedrawnasnormalclasseswiththe«entity»stereotypenotationabovetheclassname. Seealso[edit] ExecutableUML ListofUMLtools Object-orientedmodeling Dependency(UML) Relateddiagrams Domainmodel Entity–relationshipmodel Objectdiagram References[edit] ^Sparks,Geoffrey."DatabaseModelinginUML".Retrieved8September2011. ^ScottW.Ambler(2009)UML2ClassDiagrams.Webdoc2003-2009.AccessedDec2,2009 ^UMLReferenceCard,Version2.1.2,HolubAssociates,August2007,retrieved12March2011 ^"UMLderivedpropertyispropertywhichvalueisproducedorcomputedfromotherinformation,forexample,byusingotherproperties".www.uml-diagrams.org.Retrieved2019-01-24. ^OMGUnifiedModelingLanguage(OMGUML)Superstructure,Version2.3:May2010.Retrieved23September2010. ^Fowler(2003)UMLDistilled:ABriefGuidetotheStandardObjectModelingLanguage ^"UMLTutorialpart1:classdiagrams"(PDF).Archivedfromtheoriginal(PDF)on2007-01-03.Retrieved2015-07-18. ^Goodwin,David."ModellingandSimulation,p.26"(PDF).TheUniversityofWarwick.Retrieved28November2015. Externallinks[edit] WikimediaCommonshasmediarelatedtoClassdiagram. IntroductiontoUML2ClassDiagrams UML2ClassDiagramGuidelines IBMClassdiagramIntroduction OMGUML2.2specificationdocuments UML2ClassDiagrams vteUnifiedModelingLanguageActors Organizations ObjectManagementGroup UMLPartners Persons GradyBooch IvarJacobson JamesRumbaugh ConceptsObjectoriented Object-orientedprogramming Object-orientedanalysisanddesign Object-orientedmodeling Structure Actor Attribute Artifact Class Component Interface Object Package Profilediagram Behavior Activity Event Message Method State Usecase Relationships Association Composition Dependency Generalization(orInheritance) Extensibility Profile Stereotype Other Multiplicity DiagramsStructure Class Component Compositestructure Deployment Object Package Behaviour Activity StateMachine Usecase Interaction Communications Sequence Interactionoverview Timing Derivedlanguages SystemsModelingLanguage(SysML) UMLeXchangeFormat(UXF) XMLMetadataInterchange(XMI) ExecutableUML(xUML) Othertopics GlossaryofUMLterms RationalUnifiedProcess ListofUnifiedModelingLanguagetools ObjectModelinginColor Retrievedfrom"https://en.wikipedia.org/w/index.php?title=Class_diagram&oldid=1100929279" Categories:UnifiedModelingLanguagediagramsHiddencategories:ArticleswithshortdescriptionShortdescriptionmatchesWikidataArticlesneedingadditionalreferencesfromFebruary2009AllarticlesneedingadditionalreferencesCommonslinkfromWikidata Navigationmenu Personaltools NotloggedinTalkContributionsCreateaccountLogin Namespaces ArticleTalk English Views ReadEditViewhistory More Search Navigation MainpageContentsCurrenteventsRandomarticleAboutWikipediaContactusDonate Contribute HelpLearntoeditCommunityportalRecentchangesUploadfile Tools WhatlinkshereRelatedchangesUploadfileSpecialpagesPermanentlinkPageinformationCitethispageWikidataitem Print/export DownloadasPDFPrintableversion Inotherprojects WikimediaCommons Languages العربيةБългарскиCatalàČeštinaDeutschEspañolفارسیFrançais한국어हिन्दीHrvatskiBahasaIndonesiaItalianoעבריתLietuviųMagyar日本語PolskiPortuguêsРусскийShqipSlovenčinaСрпски/srpskiSuomiSvenskaதமிழ்TürkçeУкраїнська中文 Editlinks
延伸文章資訊
- 1How to show usage of static methods UML Class Diagram
To show a static method you underline the name of the static method - have a look here for more d...
- 2Class diagram - Wikipedia
In software engineering, a class diagram in the Unified Modeling Language (UML) is a type of stat...
- 39.12. static Data And Functions
Denoting static features in a UML class diagram. The UML denotes static features by underlining t...
- 4UML Class Diagrams
Class (i.e. static) methods and fields are indicated by underlining; Constant (i.e. final) fields...
- 5Day 4 軟體設計及架構---Class Diagram - iT 邦幫忙
... 結構圖中的類別圖(Class Diagram),類別圖某部分來說和物件圖(Object Diagram) ... 類別圖描述了類別的型態,以及類別之間的靜態關連(static relat...