![](/s/cache/c5/ac/c5ac78b04e044e17fe66ee2eebb3aa7e.png)
Composition Definition
Is it true to say that in a composition class B does not exist without class A or cannot exist outside of class A (B being contained inside A)?
Answer
![](/s/cache/a6/73/a6734f0835e96bbe2628c5222c7eeee6.png)
Hi Martin!
Thanks for a good question. I don't think it's a requirement of the composition. There are certainly cases when both the container and the component don't make sense without each other. But I can also imagine the composition, where the component can be used in several different containers, and it's the container that can't exist without a component.
![](/s/cache/42/4d/424d230aa859d5ebbdac6f1fb781c1c1.png)
The confusion for me comes from the first 2 lines on page 24 of "Diving": "the component can only exist as a part of the container".
![](/s/cache/a6/73/a6734f0835e96bbe2628c5222c7eeee6.png)
That's a nice catch! Here's a difference, though. In the book, I'm talking about objects—I meant that a component object can't act on its own, so when you create objects you will most likely create both the container and the component. There's no reason to create an instance of a component (make it exist) on its own. But when we're talking about classes, there's a slight distinction that I pointed out in the previous comment. I'll make a note to myself to revise this part in the book to eliminate the confusion.
Customer support service by UserEcho
That's a nice catch! Here's a difference, though. In the book, I'm talking about objects—I meant that a component object can't act on its own, so when you create objects you will most likely create both the container and the component. There's no reason to create an instance of a component (make it exist) on its own. But when we're talking about classes, there's a slight distinction that I pointed out in the previous comment. I'll make a note to myself to revise this part in the book to eliminate the confusion.