• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Confuse with whole parts relation

 
jack fe
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For example, car, engine. On line:
Some people think it is aggregation relationship. Because Engine can exists without car.
But some people think it is composition relationship. Because if the car is destroyed, the engine also is destroyed.

what is the right answer?
 
Rajiv Shr
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the engine is used in other classes as well - like Bus, aeroplane etc Then it is an aggregation. If the engine can only be associated with the Car class, and Car is responsible for instantiating/destroying the engine instance, then it is composition.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic