Search code examples
umlclass-diagram

The best way to create the class diagram


The problem is the following: A race has participants and the race has a starting line ordered by a number assigned to the participants. Each participant can use a vehicle and need to registry the information of the vehicles. So the information are: Race: name, location, time, ... Car: race start number, year of manufacture, model, ... Bike: race start number, model, wheel size, ... Horse carriage: race start number, number of horses, ...

What would be the best way to create the class diagram and get the starting line with the vehicles ordered by the race start number?

Case A: raceStartNumber are distributed in different Entities. It would be necessary to do a mapping by raceStartNumber and order the elements obtained. enter image description here

Case B: All the vehicles would be ordered on the starting line, but the vehicle class would always have two associations such as null. enter image description here

So, which case do you think is better? Would there be any other way to do it?


Solution

  • There is never a best solution. You always have tradeoffs, just that some might be less significant.

    Your 2nd example is just wrong in that you use composite aggregation rather than generalization. You would need an open triangle instead of the diamond and omit the multplicities.

    Regarding the options you should study Composition over inheritance.

    As noted by @Ister your first approach has also a major flaw. This is that the raceStartNumber is an individual property of each vehicle. And there's nothing that constraints them to be unique.

    Generally you will not model these id properties unless you have some requirement. The id of objects is implicit (in programming languages it's usually the memory address of the instance).

    I will not go into more details since this site is not meant for reviews.