I am currently working on a train simulation project for uni.
This is my class hierarchy:
RollingStock
Coach
FreightCoach
PassengerCoach
SpecialCoach
Engine
DieselEngine
ElectricEngine
SteamEngine
Trainset
My questions:
- Every coach has a unique ID. However, Engines and Trainsets share their ID-Space ("series-name"). "Name" is inherited by RollingStock and both Trainset and Engine have the attribute "series".
I've created a class "SharedIdSpace" to implement this feature. But I am not quite sure how to solve this nicely (TreeMap, ..., ?).
Now, my main problem is I have to implement the following feature:
"Rolling stock can be composed into a train. The following restrictions must be observed when composing:
- There must always be at least one locomotive/train set at the beginning or end of a valid train.
- When composing, it must always be considered whether the rolling stock has a suitable coupling at the desired composition point.
- The rolling stock that is being composed has not yet been used in another train. [...]"
How can I implement this? I'm afraid I have no useful idea.