0

I tried to solve this problem:

Draw a UML class diagram of an Object-Oriented model for a car rental company that keeps track of cars, renters and renters renting cars. Create a UML class diagram to represent this information. Showing the correct classes and relationships is enough. Do not add attributes or methods to the classes.

I was thinking the that renters and car company should be association, and car company and renters renting cars should be composition. However the proposed solution (simplified here), did not match my expectations:

enter image description here

The solution shows all the relationships as aggregation. Can someone help me understand why they all are aggregation and not association and composition as I thought?

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
Game Top
  • 23
  • 5
  • If you think the assignment isn't clear, ask the person who set it. They will probably want to know if their students don't understand what's being asked of them. This website is for programming problems, not for interpreting your homework. – Michael May 06 '21 at 21:04
  • 1
    The solution uses a common practice regarding aggregation, which does not invalidate at all your own solution. Unfortunately, the link can no longer be visualized. It would be useful for other readers in the future to see at least an extract of that diagram to better understand your concerns, and help them to understand similar issues. – Christophe May 07 '21 at 10:31
  • Links been updated. Can you please explain the difference between aggregation and association I'm kinda confused on how to distinguish the two. – Game Top May 07 '21 at 14:05

1 Answers1

2

Comments on your own analyse

I was thinking the that renters and car company should be association

Yes, this makes sense: a renter may be a customer of a car company, and reciprocally, a car company could serve several renters. Renters are not owned by a car company and reciprocally.

and car company and renters renting cars should be composition.

No: composition means exclusive ownership, and that the composed objects would in principle not survive the composite. But here, if a car company is destroyed, the renters may stay and simply go to other car companies. So no composition.

Published solution's aggregation vs. your associations

solution shows all the relationships are aggregation.

The relations that you describe seem to correspond to UML associations. The fact that the published solution uses aggregation is not necessaritly false, but it’s not recommended:

  • From the point of view of the UML specifications, the semantics are not clearly defined. So there’s no real benefit to use aggregation in a design model. See UML 2.5 p.110:

    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.
    (...) Precise semantics of shared aggregation varies by application area and modeler.

  • From the point of view of the designer, aggregation is a purely conceptual notation that does not fundamentally change the meaning of the diagram. For this reason, James Rumbaugh, a founding father of UML, once called aggregation a “modelling placebo”. I found back the quote in the book "Unified Modeling Language Reference Manual", chapter 14:

    Keep in mind that aggregation is association. Aggregation conveys the thought that the aggregate is inherently the sum of its parts. In fact, the only real semantics that it adds to association is the constraint that chains of aggregate links may not form cycle (...) In spite of the few semantics attached to aggregation, everybody thinks it is necessary (for different reasons). Think of it as a modeling placebo.

  • On the implementation side, object composition is one of the basics of OOP. Some practitioners and academics tend to represent object composition with an UML aggregation to show that the the aggregated element is a part of a whole aggregate (the UML composition would be too restrictive, especially for languages in which classes have reference semantics, as Java or C#). This argument is however discussable because the design should not be driven by the implementation techniques. Moreover, modern UML's dot notation expresses those semantics much more accurately.

  • Some really discussable choices are made on the solution diagram: If we take the example of the Renter and the Rental, from a design point of a renter has some rental contracts and would probably need to find them back. After all, the rentals are a part the renter business role. Conversely, from a contractual point of view, the renter is a party of the contract. So one could defend an aggregation in both directions, but you cannot have an aggregation on both sides at the same time. The arbitrary choice to show only one side of the truth could be confusing. And adding two aggregations in the opposite direction would not appropriately show that in fact it's the same relation. Another argument to avoid aggregation whenever possible.

Conclusion: since there’s no objective criteria to decide when to use aggregation, and in view of absence of other significant impact of using aggregation or association, just keep it simple: ignore aggregation when you read it in a diagram, and yourself, avoid using it in your own diagram and prefer association instead.

Christophe
  • 68,716
  • 7
  • 72
  • 138
  • Can you please explain the difference between aggregation and association I'm kinda confused on how to distinguish the two. – Game Top May 07 '21 at 14:06
  • @GameTop aggregation is a kind of association. If two classes are aggregated, it’s as if they were associated except that the aggregation suggests a part-whole relationship. But what is a part-whole relation ? My eye is (a part) of my body (the whole). But my dental prothesis is also a part of my body. My wedding ring as well since it’s on my finger longer than any prothesis. And meanwhile, on a shorter scala, my smartphone is also a part, since it’s an extension of my original parts and I always have it with me. The point is that “part-whole” is very difficult to define. – Christophe May 07 '21 at 14:34
  • And since it’s not possible to clearly define what’s a part-while relationship, the UML specs say that the semantics depend on the modeller’s context. Conclusion: if there’s no objective criteria to decide when to use it, and if there is no other impact of using the one or the other, just ignore it when you read it in a diagram, and yourself, avoid using aggregation in your own diagram, prefer association instead. Investing in multiplicity notation will be more useful than adding a hollow diamond – Christophe May 07 '21 at 14:40
  • It's always worth to reference UML 2.5 p. 110 where the non-existence of shared aggregation semantics is explicitely stated. – qwerty_so May 08 '21 at 09:45
  • 1
    @qwerty_so good idea ! I've edited to add the precise reference as well. I also added a couple of quotes + a final recommendation. – Christophe May 08 '21 at 11:49
  • @GameTop if the answer helped you, you can upvote it, or if it solves your question, mark it as accepted. This helps other readers to decide whether it's worth reading it or not ;-) – Christophe May 08 '21 at 11:53