3

Currently I am trying to model a UML diagram for cars. I have the problem that besides the combustion engines also electric cars exist.

When you look at the diagram, you can see that the Golf has the data type Fuel for the attribute consumes, while the e-Golf has the data type EnergyType.

How would you adapt this diagram?

UML diagram

MerklT
  • 803
  • 7
  • 18

2 Answers2

4

Inheritance is meant differently. You already define consumes an enumeration in the abstract class. Now in the inheriting ones you do not override this attribute but just assign fixed values. Plus you use a wrong notation in that case. It would be rather consumes: Energytype = electrical energy (etc.). This type anyway is superfluous since you would have it in the class type itself. A concrete electric car is of the type you want. So that enumeration would contain the possible concrete class types (if needed at all). Now you should rather concentrate on what the different car types are. The only common thing is probably the chassis which will be defined in the abstract car.


N.B. thinking this way of cars is what the dinosaurs actually do and which is why they have so much trouble. E-cars are much more different than classic cars. Basically you need to go back to the seats for humans inside for the abstract car.


Amendment enter image description here

could be a way to express a car (there are lots and lots of ways to show variants and it takes weeks and months to get to something appropriate for cars). You see that the abstract car (written in italics) has no attributes but just associations with role names. Some to abstract classes and one to a concrete class (note that this is just something meant as example). The abstract classes just have associations and contain attributes which are agreed to be common to that thing.

Now if you're building some concrete car configuration you will only have concrete classes:

enter image description here

The MySuperNewCar has an electric drive with 4 wheels and 2 leather seats. I repeated the abstract classes in this diagram. But that's not needed (since you probably would already guess so).

So, thats one way to describe a car. There are much more ways which need long discussions. In any way you should get a consultant aboard who's talking UML fluently (in other words who's good at modeling things).

qwerty_so
  • 35,448
  • 8
  • 62
  • 86
  • Thank you very much, I've learned a lot again. Just to understand: if I assign an attribute in a derived class, do I still write the data type again like `consumes: Energytype = electrical energy` or simply, `consumes = electrical energy`? – MerklT Jul 31 '19 at 10:04
  • That's not a part of the inheritance itself. I will elaborate a bit more on my answer, but I'm busy at the moment. If you happen to be located in Fallersleben we eventually might meet personally ;-) – qwerty_so Jul 31 '19 at 10:43
  • I would appreciate that. Unfortunately I am not located in Fallersleben ;) – MerklT Jul 31 '19 at 11:19
  • There you are (I had a bit more time right now). Note that the `Seat` should have `noOfPersons:Int = 1` (too lazy to fix the image...) – qwerty_so Jul 31 '19 at 11:36
  • Wow that is very interesting, thank you for all the effort. I will definitely take over one or the other. – MerklT Jul 31 '19 at 11:45
  • @qwerty_so, why did you use the realization relationships (dashed arrows) instead of the generalization relationships (solid lines)? – www.admiraalit.nl Jul 31 '19 at 11:53
  • @www.admiraalit.nl It's just a tiny difference. Here you emphasize that you are going from abstract to real. A Generalization would do as well, but the emphasis is (I think) important here. – qwerty_so Jul 31 '19 at 12:07
0

I would advise to use different names for attributes with different types. Instead of 'consumes' you could use 'energyType' and 'fuelType'.

www.admiraalit.nl
  • 5,768
  • 1
  • 17
  • 32