UML Association vs Aggregation vs Composition
文章推薦指數: 80 %
If two classes in a model need to communicate with each other, there must be a link between them, and that can be represented by an association (connector). Home Support Current:UMLAssociationvsAggregationvsComposition UMLAssociationvsAggregationvsComposition AssociationvsAggregationvsComposition Association AssociationvsAggregationvsComposition GeneralizationvsSpecialization GeneralizationvsInheritance RelatedLinks Considerthedifferencesandsimilaritiesbetweentheclassesofthefollowingobjects:pets,dogs,tails,owners. Weseethefollowingrelationships: ownersfeedpets,petspleaseowners(association) atailisapartofbothdogsandcats(aggregation/composition) acatisakindofpet(inheritance/generalization) Thefigurebelowshowsthethreetypesofassociationconnectors:association,aggregation,andcomposition.WewillgoovertheminthisUMLguide. Thefigurebelowshowsageneralization.WewilltalkaboutitlateroninthisUMLguide. LearnUMLwithFreeUMLTool AreyoulookingforaFreeUMLtoolforlearningUMLfaster,easierandquicker?VisualParadigmCommunityEditionisaUMLsoftwarethatsupportsallUMLdiagramtypes.Itisaninternationalaward-winningUMLmodeler,andyetitiseasy-to-use,intuitive&completelyfree. FreeDownload Association Iftwoclassesinamodelneedtocommunicatewitheachother,theremustbealinkbetweenthem,andthatcanberepresentedbyanassociation(connector). Associationcanberepresentedbyalinebetweentheseclasseswithanarrowindicatingthenavigationdirection.Incaseanarrowisonbothsides,theassociationisknownasabidirectionalassociation. Wecanindicatethemultiplicityofanassociationbyaddingmultiplicityadornmentstothelinedenotingtheassociation.TheexampleindicatesthataStudenthasoneormoreInstructors: Asinglestudentcanassociatewithmultipleteachers: TheexampleindicatesthateveryInstructorhasoneormoreStudents: Wecanalsoindicatethebehaviorofanobjectinanassociation(i.e.,theroleofanobject)usingrolenames. AssociationvsAggregationvsComposition Thequestion"Whatisthedifferencebetweenassociation,aggregation,andcomposition"hasbeenfrequentlyaskedlately. AggregationandCompositionaresubsetsofassociationmeaningtheyarespecificcasesofassociation.Inbothaggregationandcompositionobjectofoneclass"owns"objectofanotherclass.Butthereisasubtledifference: Aggregationimpliesarelationshipwherethechildcanexistindependentlyoftheparent.Example:Class(parent)andStudent(child).DeletetheClassandtheStudentsstillexist. Compositionimpliesarelationshipwherethechildcannotexistindependentoftheparent.Example:House(parent)andRoom(child).Roomsdon'texistseparatetoaHouse. CompositionExample: Weshouldbemorespecificandusethecompositionlinkincaseswhereinadditiontothepart-ofrelationshipbetweenClassAandClassB-there'sastronglifecycledependencybetweenthetwo,meaningthatwhenClassAisdeletedthenClassBisalsodeletedasaresult AggregationExample: It'simportanttonotethattheaggregationlinkdoesn'tstateinanywaythatClassAownsClassBnorthatthere'saparent-childrelationship(whenparentdeletedallitschild'sarebeingdeletedasaresult)betweenthetwo.Actually,quitetheopposite!TheaggregationlinkisusuallyusedtostressthepointthatClassAinstanceisnottheexclusivecontainerofClassBinstance,asinfactthesameClassBinstancehasanothercontainer/s. Summingitup- Tosumitupassociationisaverygenerictermusedtorepresentwhenoneclassusedthefunctionalitiesprovidedbyanotherclass.Wesayit'sacompositionifoneparentclassobjectownsanotherchildclassobjectandthatchildclassobjectcannotmeaningfullyexistwithouttheparentclassobject.IfitcanthenitiscalledAggregation. GeneralizationvsSpecialization Generalizationisamechanismforcombiningsimilarclassesofobjectsintoasingle,moregeneralclass.Generalizationidentifiescommonalitiesamongasetofentities.Thecommonalitymaybeofattributes,behavior,orboth.Inotherwords,asuperclasshasthemostgeneralattributes,operations,andrelationshipsthatmaybesharedwithsubclasses.Asubclassmayhavemorespecializedattributesandoperations. SpecializationisthereverseprocessofGeneralizationmeanscreatingnewsub-classesfromanexistingclass. ForExample,aBankAccountisoftwotypes-SavingsAccountandCreditCardAccount.SavingsAccountandCreditCardAccountinheritthecommon/generalizedpropertieslikeAccountNumber,AccountBalance,etc.fromaBankAccountandalsohavetheirspecializedpropertieslikeunsettledpaymentetc. GeneralizationvsInheritance GeneralizationisthetermthatweusetodenoteabstractionofcommonpropertiesintoabaseclassinUML.TheUMLdiagram'sGeneralizationassociationisalsoknownasInheritance.WhenweimplementGeneralizationinaprogramminglanguage,itisoftencalledInheritanceinstead.Generalizationandinheritancearethesame.Theterminologyjustdiffersdependingonthecontextwhereitisbeingused. LearnUML.DrawUML. DoyouwantaUMLtoolthatcanhelpyoulearnUMLfaster&moreeffectively?VisualParadigmCommunityEditionisafreeUMLsoftwarethatsupportsallUMLdiagramtypes.ItsUMLmodelerisaward-winning,easy-to-useandintuitive. FreeDownload RelatedLinks WhatisUnifiedModelingLanguage? ProfessionalUMLtool Turneverysoftwareprojectintoasuccessfulone. TryVisualParadigmFree Weusecookiestoofferyouabetterexperience.Byvisitingourwebsite,youagreetotheuseofcookiesasdescribedinourCookiePolicy. OK
延伸文章資訊
- 1Association Class | Enterprise Architect User Guide
An Association Class is a UML construct that enables an Association to have attributes and operat...
- 2【UML】Class Diagram 類別圖(下):Relationships 關係
Relationships 關係Instance-level 物件層級Dependency 依賴Association 關聯...
- 3UML Association - Javatpoint
Association is the semantic relationship between classes that shows how one instance is connected...
- 4{UML 2.0} 關聯類別(association class) - Kenmingの鮮思維
An association class connection is a UML construct that allows an association connector to have a...
- 5I don't understand association class - UML class diagram
An association class is both a class and a relation, when you implement it in a language like C++...