Train - Wagon class diagram


#1

Hello, I have doubts on approaching doing this.

I have a Train class and a Wagon class. There are three types of wagon: FirstClass, TouristClass and DiningCar. Each of these types has the same properties and methods, the only difference between them is their multiplicity with the Train class.

Each train class has one and only one DiningCar wagon, at least one FirstClass wagon and at least one TouristClass wagon.

What is the best way to do this. Should the classes FirstClass, TouristClass and DiningCar inherit from the Wagon class, make them empty and then relate them to the train class? Or there is other approach?


#2

Depends. What is it you’re trying to do here? UML knows several types of diagrams, so it would be useful to know what you’re working on :wink:

But focusing on the classes, and a class diagram, I’d probably create all 4 individual classes, set up the diagram, set their relationships and call it a day.