Re: Aggregation vs composition
From: Matthias Hofmann (hofmann_at_anvil-soft.com)
Date: 05/04/04
- Next message: Thomas Gagné: "Re: Why is OO Popular?"
- Previous message: Eric Kaun: "Re: Why is OO Popular?"
- In reply to: Daniel T.: "Re: Aggregation vs composition"
- Next in thread: Michael Rauscher: "Re: Aggregation vs composition"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 4 May 2004 15:48:51 +0200
> If two objects (A & C) share a reference to a third object (B), then A
> and C must cooperate in order to determine the disposition of B. Neither
> A nor C can be said to have "sole responsibility" for B. This is basic
> logic.
No, this is not logical at all. Sharing a reference does not mean sharing
responsibility for the destruction. Furthermore, only one object can be
responsible for the destruction of a part at all, as otherwise the object
could be destroyed twice (or more) - that is basic logic!
The object is destroyed by its owner, and this goes for C++ as well as Java.
In C++, the programmer is the one who decides who is the owner of a pointer
while in Java, this is done by an internal reference count: a reference in
Java is nothing but an object that destroys the object referenced by it when
the reference count is about to reach zero.
Maybe a composition relationship does not make sense for Java, but then
don't use it - the UML has not been designed just for Java programmers!
> If I am wrong then the following three diagrams are exactly equivalent:
No. If you are wrong, then the following three diagrams are NOT exactly
equivalent.
> 0..1
> [A]----------[B]-----[C]
>
> 0..1
> [A]<>--------[B]-----[C]
>
> 0..1
> [A]<#>-------[B]-----[C]
>
>
> Lastly, it cannot be denied that the ability to hide the objects one
> uses in its implementation is very important. To me, this means that a
> modeling notation that has no way of expressing such a relationship is
> flawed.
The idea of hiding the objects you use in your implementation is expressed
by not providing any operations to access these hidden parts.
> Where in the specification does it say that a part object in a composite
> can be shared?
The specification tells you so by not forbidding it. You are even allowed to
remove a part from a composite and have someone else take responsibility for
it.
Regards,
Matthias
- Next message: Thomas Gagné: "Re: Why is OO Popular?"
- Previous message: Eric Kaun: "Re: Why is OO Popular?"
- In reply to: Daniel T.: "Re: Aggregation vs composition"
- Next in thread: Michael Rauscher: "Re: Aggregation vs composition"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|