I won't provide the diagram because this is obviously some kind of homework. But here some hints:
Each train class has one and only one
DiningCar wagon, at least one
FirstClass wagon and at least one
TouristClass offer different services and behaviors. For example, you wouldn't expect
FirstClass to offer a function
getNumberOfFreeRestaurantTables(), while you would expect
DiningCar to do. So specializing the
Wagon seems a good idea.
Each train class has one and only one ... at least one ...
and at least one ....
You have to translate this into associations between Train and your specialized
Wagon classes. For each association you can specify the multiplicity.
The more elaborate
As there is a whole-part association between
Train and its
Wagons, you may consider using an aggregation instead of a normal association.
As a wagon could be removed from one train and attached to another train, we could assume that aggregation is the correct alternative, and that composition would not suit the needs.
Are there other approaches ?
Sure ! You could not specialize
Wagon, and let
Wagon have some property that tells if which kind it is.
The aggregation association between
Wagon should then have a multiplicity telling that there are at least 3
Wagons (one of each).
But how would you then express that there is exactly one
DiningCar at at least on of each of the other kind ? Well, you could consider writing a constraint for the association. The OCL expression to express this constraint formally is however much less self-explanatory than our initial approach with specialization...