views:

59

answers:

2

In OOP modeling, is there any distinction between a "has-a" relationship and a "composed-of" relationship?

+1  A: 

Not really, since both indicate that a parent object contains an instance of a child class. It's mostly a semantic difference where "has-a" represents an association between two different objects, where "composed-of" indicates that the child is an integral part of the parent.

MrGumbe
An interesting question regarding the other answer is whether an engine can have an identity independent of the car in which it is mounted.I would assert that the answer is yes. I bought a replacement engine for a car once. I would hope that the installers could distinguish the engine they removed from the one they installed.Still, in many applications, an engine could be modeled as a subobject of car with no harm done.
Walter Mitty
+4  A: 

Both statements usually mean composition.

But it seems to me that composed-of always means composition while has-a sometimes can mean aggregation (but not in the picture below). In UML it looks like:

alt text

Roman