Thank you for your helpful article. I am still a bit confused about one thing. Your code examples of chair/table and chair/chairleg are effectively the same yet they seem to be archetypal for the different situations. It would be nice if the code examples would more clearly show how the with composition the chairleg cannot exist without the chair. However, it seems to me that it can. It is being created before the chair and then passed into the chair constructor. So at least momentarily it can live without the chair. As a suggestion, maybe if chair instantiated the chairleg its constructor it would be more composition-like? No?
Yes. You're right. That's what I meant, ChairLeg can exist without Chair, but I did not mention it quite clearly. General speaking, I want to emphasize that "In composition, subclasses' life cycle depends directly on superclassโs life cycle and vice versa. In aggregation, the subclasses and superclass have their own life cycle.". Thanks for your comment. Have a good day!
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Thank you for your helpful article. I am still a bit confused about one thing. Your code examples of chair/table and chair/chairleg are effectively the same yet they seem to be archetypal for the different situations. It would be nice if the code examples would more clearly show how the with composition the chairleg cannot exist without the chair. However, it seems to me that it can. It is being created before the chair and then passed into the chair constructor. So at least momentarily it can live without the chair. As a suggestion, maybe if chair instantiated the chairleg its constructor it would be more composition-like? No?
Yes. You're right. That's what I meant, ChairLeg can exist without Chair, but I did not mention it quite clearly. General speaking, I want to emphasize that "In composition, subclasses' life cycle depends directly on superclassโs life cycle and vice versa. In aggregation, the subclasses and superclass have their own life cycle.". Thanks for your comment. Have a good day!