1

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

  • Is this repeat of: http://stackoverflow.com/questions/731802/what-is-the-difference-between-composition-and-association-relationship – Sunny Apr 27 '10 at 13:10
  • Sunny, yes, thanks, looks like a repeat. I didn't see that one. –  Apr 27 '10 at 13:20

2 Answers2

4

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
(source: atomicobject.com)

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
Roman
  • 64,384
  • 92
  • 238
  • 332
1

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.

cortijon
  • 983
  • 6
  • 13
  • 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 Apr 28 '10 at 13:18