Aggregation and composition in various relationships

3

Given a class A, let's say that the relation between this class A and a class B is composition, where A is the class "all" and B is the class "part". Given a third class C, can there be another composition between B and C, so that in this new relationship C is the "whole" and B the "part"? Here's an example below of what this would look like in the class diagram:


Anotherdoubt:havingaclassBisitpossibleforittorelatetoaclassAbymeansofacompositionandaclassCbymeansofanaggregation?Here'sanexamplebelowofwhatthiswouldlooklikeintheclassdiagram:

    
asked by anonymous 11.01.2016 / 21:40

1 answer

2
The composition relation is represented by an arrow from the "host" class with a colored diamond (from black) to the "part" class (with no symbol at this end, but at most specifying the total number of that part).

For example, it assumes having a Pessoa class, and, as we well know, a person is "made up" by legs and arms. Here you could create a composition relation from the Pessoa class with a colored diamond to the Perna and Braço class.

Notethatyoucouldhavespecifiednumber2atthePernaandBraçoends,becausefortunatelymostpeoplehave2armsandlegs.

Inyourfirstspecificcase,onthesecondarrowthediamondshouldbeonthepartoftheCclass,sinceyouwantCasthewhole(orthe"host" class).

In general, you can have the combinations of relationships that you like. Clearly some have more sense than others. Even though your second diagram does not represent what you would like to get, because you say you want a "composition" between A and B , but in reality when you use an empty diamond it means "aggregation". Most probably you've traded the two relationships.

There are good articles online to understand more about these relationships:

Among many others.

    
11.01.2016 / 22:29