0

According to my understanding, a part object can not exist without a composite object. But in this diagram, according to the given multiplicity, B type object can be without A type object. Is it possible? What is the meaning of that?

enter image description here

Ju Ju
  • 199
  • 1
  • 13

1 Answers1

3

According to UML spec (9.5.3)

Composite aggregation is a strong form of aggregation that requires a part object be included in at most one composite object at a time. If a composite object is deleted, all of its part instances that are objects are deleted with it.

The diagram is absolutely correct (you will find such example even on UML exam).

The semantics is that the object of class B - if in composition - is a part of A (A is responsible for B and when A is deleted all objects that are at the moment its parts will be deleted as well). An object of type B that is part of one object of class A cannot simultaneously be a part of other object of type A. However it is possible that is an object of type B that is not a part of any object of type A.

This is your case. So object of type B either is not part of any object of type A (and it is possible in your model) or is a part of exactly one object of type A.

Ister
  • 5,958
  • 17
  • 26
  • So how can B have a 0-multiplicity if it's removed when not associated? – qwerty_so Jun 01 '16 at 18:01
  • 1
    B doesn't have to be a part of A. It can be just a separate object, or can be a part of different object (e.g. C). Moreover the specification doesn't say the element B will be removed when detached from A. It says only that element B will be destroyed if it is a part of A at the moment when A is destroyed. Specification states clearly that it is possible that model can give possibility to detach B from A. If it has to be reattached to other object of type A or can remain a totally separate object depends on model. – Ister Jun 01 '16 at 18:39
  • This anwer is correct. It is not required that the a part object (B) is part of an other aggregat object (A). But a part object can only be part of one aggregate objected; irregardless of how many different compositions are defined, as the composition has to be unique. – sim Jun 01 '16 at 19:00
  • It's not true that a composition implies that all components MUST be destroyed when the composite is destroyed, see my SO answer http://stackoverflow.com/a/27889087/2795909 – Gerd Wagner Jun 02 '16 at 23:19
  • @gwag, I'm fully aware of this details. Actually the statement in the specification about prior removing of a part from a whole isn't 100% clear as it can be read either that this removal can happen as a step of object destruction or only somewhere in the whole lifecycle before its destruction. Yet if the object was a part and wasn't removed prior to or as a part of destruction process it would be destroyed together with the whole. Which I meant by writing "element B will be destroyed if it is a part of A **at the moment** when A is destroyed". – Ister Jun 03 '16 at 06:35