I am confused about how to decide aggregation vs composition for Has-A relation. Let me explain my doubt with example of BookMyShow App(BMS) which is Show booking platform and assume a Show can be booked for a Movie, Standup comedy or any such event.
Now let’s say for some usecase we have this relationship in our code, i.e. a Movie has list of Shows.
Object level thinking:
A Movie object has a list of show objects, if I delete this movie object due to any reason, all these show objects will make no sense as they were corresponding to that movie, so this relationship is Composition.
Class level thinking:
Movie class has list of Show, if I delete Movie class from my app, will there be no use of Show class? No, because we have other events as well which will have Show class, so this way Show class can exist even without Movie class, this way Movie has shows is Aggregation relation.
Now my questions:
- Which way of thinking is correct out of the two?
- Am I wrong in any of the above ways somewhere and due to which the end result of type of relationship is different? Am I missing something in any approach?