Can more than one objects aggregate or acquaint or instantiate the same object?

二次信任 提交于 2019-12-02 13:51:29

To my understanding and the common definitions I know, Composition is an association where the lifetime of the associated objects is tied to the lifetime of the owner. Aggregation describes an association where the lifetime of the aggregated objects is independent from the lifetime of the owner. Acquaintance is the same as association.

According to this definition an object can be aggregated by multiple owners in an aggregate association. If the association is of type composition then sharing is by definition not intended.

Association or acquaintance are more generic description of a relationship between objects. So it depends on the details of the relationship if a single object can have multiple owners. But when being that generic, it is generally possible.

Wikipedia Object composition and aggregation

But I think there exists another definition which was introduced by Martin Fowler. It's the one you were quoting. To me this is the less known definition since the one that I rendered is defined in the UML rules which are widely spread and have become a de facto standard. According to M. Fowler's definition aggregation is equal to composition whereas acquaintance matches the UML definition of aggregation.

So the answer to your questions is, when looking through the eyes of M. Fowler: the rules for composition apply when talking about Fowler's aggregation which means multiple owners can't aggregate the same objects and in terms of acquaintance the rules of the in the UML defined aggregation association apply meaning that multiple owners can acquaint the same objects independently (from their lifetime).0

And of course you can create instances of an object as often as you want or as memory is available and where you want. The object or the class is only the definition whereas the instance (as a result of the instantiation) is the actual allocated memory area to store data of the object (e.g. fields). The class definition describes the layout of this allocated memory area.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!