2

According to the answer here and this article there.

table 1

Life-cycle Composition (Relation A) Aggregation (Relation B)
Whole(Parent) independent of part (eg. building) independent of part (eg. room)
Part(Child) depends on whole (eg. apartments) independent of whole (eg. chair)
---- ---- ----
Example A building has apartments, if the building gets destroyed then the apartments will cease to exist, but if you destroy the apartments in the building then the building will remain. A room has a chair in it, if you break the chair the room will still exist, and if you take the chair out and destroy the room the chair will still exist.

1- Is it right? and if it is? what if:-

table 2

Life-cycle Relation X Relation Y
Whole(Parent) depends on part (eg. apartment building) depends on part (eg. editDataActivity)
Part(Child) depends on whole (eg. apartments) independent of whole (eg. Data)
---- ---- ----
Example An apartment building has apartments, if the apartment building gets destroyed then the apartments will cease to exist, and if you destroy the apartments in the apartment building then the apartment building will be destroyed because it no longer matches its definition. editDataActivity has Data, editDataActivity can't exist without Data to be edit, so whole depend on part, but Data can exist without editDataActivity, so part independent of whole.

2- What is the Relation Y and X?

I can guess the Relation X, because in "Object-Oriented-Design Course Notes" on Coursera, it said:

Composition is one of the most dependent of the decomposition relationships. This relationship is an exclusive containment of parts, otherwise known as a strong “has-a” relationship. In other words, a whole cannot exist without its parts, and if the whole is destroyed, then the parts are destroyed too. In this relationship, you can typically only access the parts through its whole. Contained parts are exclusive to the whole. An example of a composition relationship is between a house and a room. A house is made up of multiple rooms, but if you remove the house, the room no longer exists.

Then from the first italic bold sentence, we can say that whole depends on part and from the second italic bold sentence, we can say that part depends on whole, and that's exactly the Relation X.

3- Is it right or there is a wrong with that definition?

Geert Bellekens
  • 12,788
  • 2
  • 23
  • 50
  • _whole depends on part_ already tells that you talk about composite aggregation. Of course it then depends on tha part. You are entering the question from the back door. – qwerty_so Jul 07 '22 at 19:42
  • 1
    Don't try to understand the composition with examples in the real life. In real life, nothing disappears, even when the whole disappears. In software, the whole can delete the parts from the computer memory. It can be very misleading to apply concepts from computers 1:1 to the real life. – Axel Scheithauer Jul 09 '22 at 07:32

1 Answers1

-1

Dependency is the most generalized relationship between (say) classes. Therefore, if there is an association, generalization, whole-part (aggregation or composition), realization (class & interface) they are all dependencies. You question refers to whole-part relationship, therefore, yes, a whole most certainly has a dependency on it's parts. Your interpretation of the first sentence is correct (however, there are other views, in other disciplines, we shall not discuss the same here). The interpretation of the second sentence is, in a composition, if the whole is destroyed, the parts are destroyed as well; the parts are not dependent on the whole in any way, just that the life-cycle of the parts are controlled by the whole. In an aggregation, the life-cycle of the parts are not controlled by the whole.

refer: Difference between association and dependency?

refer: http://www.cs.sjsu.edu/~pearce/modules/lectures/uml/class/association

Ironluca
  • 3,402
  • 4
  • 25
  • 32
  • So we can sum up by saying that:- 1- There is a difference in meaning between “A cannot exist without its B” and “if B is destroyed, then A are destroyed too.” The first means that A depends on B, and the second means that A’s life cycle (depends on/is controlled by) B, NOT that A is dependent on B. 2- The criterion for whether the relationship is a composition or a aggregation is that the parent controls the child’s life cycle and not the other way around. – Mohamed Sallam Jul 03 '22 at 21:15
  • 3- Relationship x is composition relationship because the parent controls the life cycle of the child, and is dependency relationship because the parent depends on the child. So do I represent each relationship with the own arrow according to the UML, or is the composition arrow enough? 4 - Relationship y is aggregation because the life cycle of the child is independent of the parent, and is dependency relationship because the parent depends on the child. So do I represent each relationship with the own arrow according to the UML, or is the aggregation arrow enough? – Mohamed Sallam Jul 03 '22 at 21:15
  • 5- Relationship A = composition only and there is no dependency relationship, but composition is just a type of dependency relationship, and relationship B = aggregation only and there is no dependency relationship, but aggregation is just a type of dependency relationship. – Mohamed Sallam Jul 03 '22 at 21:16