2

Which of the following represents an aggregate relationship (has-a)?

  1. Parent and child.
  2. Animal and dog.
  3. teacher and computer
  4. phone and fax machine
  5. All of the bove

The correct answer is 3. But why is not 1 also an aggregate relationship?

Avv
  • 1,159

1 Answers1

1

It depends on your application. Using UML specification:

Sometimes a Property is used to model circumstances in which one instance is used to group together a set of instances; this is called aggregation.

whereby there are different possibilities:

  • none: Indicates that the Property has no aggregation semantics.
  • shared: Indicates that the Property has shared aggregation semantics. Precise semantics of shared aggregation varies by application area and modeler.
  • composite: Indicates that the Property is aggregated compositely, i.e., the composite object has responsibility for the existence and storage of the composed objects.

Now, the key difference between composition and aggregation is that "in composition, when the owning object is destroyed, so are the contained objects", while aggregation "does not imply ownership" (see wikipedia).

The child can not survive without its parent in this scenario. Whether this makes sense or not depends on the used model.

David Scholz
  • 2,006
  • Thank you. What can we say about phone and fax machine? I guess this is also ownership as fax owns the phone, is not it and both can not live independently thus t aggregate but composite? – Avv Jan 31 '21 at 14:53
  • 1
    Yes, I would agree, but this also depends. Is the phone "attached" to the fax and is therefore unusable without it, or are we using two different devices? This depends on your application domain as well. – David Scholz Jan 31 '21 at 15:43
  • The instructor could play with this question then as he likes? Most questions like these came without context, so how you could know? – Avv Jan 31 '21 at 15:47
  • 1
    I remember this problem very well from my Database exams a long time ago. In your provided example ony one out of five is correct. Choose the most likely, which is obviously the third ($5$ is wrong because $2$ is obviously wrong, and if I had to choose between $1$, $3$ or $4$, answer $3$ is the most likely or the "most" correct if you want to call it so). If you need to assign each one, then it depends on your course and your instructor, which I'd ask him or her directly. – David Scholz Jan 31 '21 at 15:54