Tell me, please, what is the difference between black and white rhombus in class inheritance in UML diagrams?

alt

    1 answer 1

    An open rhombus is an aggregation relationship. Aggregation is the ratio of the whole part.

    • aggregate ( MyEntityClass ) can exist both independently of parts ( MyClass ), and with them;
    • parts can exist independently of the unit
    • the unit is somewhat incomplete in the absence of parts
    • parts can belong to several units simultaneously

    Filled diamond - composition. Composition is a strict form of aggregation.

    • At the same time, parts ( MyClass2 ) can belong to only one composite ( MyEntityClass ) - joint ownership of parts is impossible.
    • the composite is solely responsible for all its parts; This means that he is responsible for their creation and destruction.
    • the composite can release parts by transferring responsibility for them to another object
    • in case of destruction of a composite, he must destroy all his parts or transfer responsibility for them to another object.

    The key difference between composition and aggregation is that parts do not have independent life outside the whole (composite) in composition. Moreover, in a composition, each part belongs to one and only one whole (composite), whereas during aggregation, a part can be shared by several whole (aggregates) .

    D. Arlow, A. Neustadt - "UML2 and Unified Process"

    • Oh, it's hard ... If it doesn't bother you, please give an example of one and the other in any language, you can even in pseudo-code. - The secret of the FSB