Class diagram: Can I share a composition?

孤人 提交于 2019-12-06 07:28:44

Yes, it is possible and one of the best example is that of a pool (the struture, not the one with water...). In a pool, the pool manager has a composition relationship with all the elements. The pool manager manages the allocation of elements to "users" as required. The users are now sharing these agregate elements.

It is important to note that the pool manager is the owner of the pool elements and is, therefore, responsible for their creation and destruction (as required to maintain the pool within prescribed limits) and needs to keep track of their allocation. The pool elements can also only have one owner. The pool's user can only borrow and return an element in this scenario.

In your scenario, I would suspect you can use either aggregations or just a simple association, keeping in mind that the owner of the object (the one with the composition) can destroy it...

Taking your car-part of the question, if you mean if it is legal to use both white and black diamonds in the same picture like in this one..

..then I think it is perfectly valid and doable.

In my understanding the black diamonds just represent the "ownership", saying who is responsible for releasing memory and chaining the calls to destructors and invalidating the other weak pointers (those coming from lines with white diamonds and lines without diamonds)

Another picture where both diamonds co-exist at the same time can be found at Kirill Fakhroutdinov's site under..

EDIT: after @gwag comment http://www.uml-diagrams.org/library-domain-uml-class-diagram-example.html (see the Library class)

..http://www.uml-diagrams.org/dicom-real-world-uml-class-diagram-example.html (see the Visit class)

Your main question ("are composites allowed to be shared with any other kind of relation in a uml class diagram") is not very well expressed. You probably refer to components and not to composites. Indeed, a wheel, as a part/component of a car, cannot be shared with other cars (at the same time), while an employee, as a part of a company or team, can be shared with several other companies or teams..

But this non-shareability concerns only the two classes involved in the composition relationship (Car and Wheel, Company and Employee). And it does not restrict component objects to participate in other relationships instantiating other associations.

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