Aggregation and composition in various relationships

Asked

Viewed 353 times

3

Given a class A, let us 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 is the "part"? Here is an example below of how this would look in the class diagram:

Multiplas composições
Another question: having a class B is it possible that it relates to a class A by means of a composition and a class C by means of an aggregation? Here is an example below of how this would look in the class diagram:

Composição/agregação

1 answer

2


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

For example, suppose to have a class Pessoa, and, as we well know, a person is "composed" of legs and arms. Here you could create a composition relationship from the class Pessoa with a colorado diamond up to class Perna and Braço.

inserir a descrição da imagem aqui

Note that could have specified the number 2 at the ends Perna and Braço, because fortunately most people have 2 arms and legs.

In your first specific case, in the second arrow the diamond should be part of the class C, since you want to C as a whole (or the class "host").

In general, you can have the relationship combinations you want. Clearly some have more meaning than others. Yet 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 likely you exchanged the two relationships.

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

Among many others.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.