Challenge 3: Playing with Cars and Engines! - doesn't this represent a "part-of" relationship?

Since the ToyotaEngine object doesn’t exist independently of Toyota object (based on the solution for this challenge), my understanding is that it represents a composition (part-of) relationship. However, in the UML diagram for the challenge, the relationship is shown as “has-a”.
Could someone clarify this, please? Thank You.

According to the definition, in a “part-of” relationship one class object has to be a component of another class. That means an instance of a component class can only be used inside the containing class.

In the solution, the ToyotaEngine class is not a component class of Toyota. In other words, it is not defined inside the Toyota class and can be used anywhere else. That is why it is a “has-a” relationship and not a"part-of" relationship.

Doesn’t this conflict with the definition and example in lesson 3 of the same section of the course titled composition?
Here is the link for reference: Composition - Learn Object-Oriented Programming in Java

1 Like

Thank you for the correction. The content has been changed. Feel free to reach out in case of any queries.

1 Like