"Computer science is no more about computers than astronomy is about telescopes" - Edsger Dijkstra
"Computer science is no more about computers than astronomy is about telescopes" - Edsger Dijkstra
"A composite is an agregate with the additional constraints that an object may be part of only one composite and that the composite object has responsability for the disposition of all its parts, that is, for their creation and destruction".
"Computer science is no more about computers than astronomy is about telescopes" - Edsger Dijkstra
Originally posted by Ken Blair:
Is this still composition?
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Originally posted by Ilja Preuss:
As far as I can tell, it is *more* than composition. Composition, as defined by UML (and as explained by Uncle Bob) doesn't hold an object from being exposed to the outside. In fact it doesn't even require that it is created and destroyed by the same parent object, as far as I know.
Composition
A form of agregation with strong ownership and coincident lifetime of parts by the whole. A part may belong only to one composite. Parts with non-fixed multiplicity may be created after the composite itselt. But once created, they live and die with it (that is, they share lifetimes). Such parts can also be explicitly removed before the death of the composite. Composition may be recursive.
Semantics
There is a strong form of aggregation called composition. A composite is an agregate association with the additional constraints that an object may be part of only one composite at a time and that the composite object has sole responsibility for the disposition of all its parts. As a consequence of the first constraint, the set of all composition relationships (over all associations with the composition property) forms a forest of trees made of objects and composition links. A composited part may not be shared by two composite objects. This accords with the normal intuition of physical composition parts (one part cannot be a direct part of two objects, although it can indirectly be part of multiple objects at different levels of granularity in the tree).
By having responsibility for the disposition of its parts, we mean that the composite is responsible for their creation and destruction. In implementation terms, it is responsible fro their memory allocation. During its instantiation, a composite must ensure that all its parts have been instantiated and correctly attached to it. It can create a part itself or it can assume responsibility for an existing part. But during the life of the composite, not other object can have responsibility for it. This means that the behavior for a composite class can be designed with knowledge that no other class will destroy or deallocate the parts. A composite may add additional parts during its life (if multiplicieties permit), provided it assumes sole responsibility for them. It may remove parts, provided the multiplicities permit and responsibilites for them is assumed by another object. If the composition is destroyed, it must either destroy all its parts or else give responsibility for them to other objects.
This definition of composition works well with garbage collection. If the composite itself is destroyed, the only pointer to the part is destroyed and the part becomes inaccessible and subject to garbage collection.
An object may be part of only one composite at a time. This does not preclude a class from being a composite part of more than one class at different times or in different instances, but only one composition link must exist at one time for one object.
Originally posted by Edwin Dalorzo:
I hope this helps to set this clear.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
"Computer science is no more about computers than astronomy is about telescopes" - Edsger Dijkstra
Not really. For example, "but only one composition link must exist at one time for one object" doesn't say whether there can be non-composition links of an object beside the one composition link.
But how did the elephant get like that? What did you do? I think all we can do now is read this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
|