I have a scenario about railway system. In this system there are
Rails
- Normal : The rails don’t have any extern support.
- Electrified : The rails supported with electricity.
Trains
- High-Speed Train :This type of trains track on electrified rails.
- Passanger Train : Passanger trains can move either electrified or normal rails.
- Accelerated Passenger Train : This type of trains track on electri开发者_如何学编程fied rails. It is evolved from Passenger Train .
- Goods Train : A goods train can move both of rails but its weight makes it harmful for electrified rails. So it is not preffered.
I want to show the relation between trains and rails using uml. Obviously trains dont have rails. They just use them. But I couldn't find the true way to show the relation in class diagram. Should i use another diagram or what? thanks in advance..
I believe you should just model it as a dependency in UML. It is usually a supplier / client relationship. In your case, the rails would be the supplier and the train the client (as in the train uses the infrastructure the rails provide). It would be a dashed arrow from 'Train' to 'Rails'. That's how I would do it.
Thanks for your answer Razzie. Here is how I made it:
I created an abstract class called "Rail". Then derived 2 sub-classes "Normal" and "Electrified". Created abstract class "Train", derived sub-classes "HighSpeedTrain", "PassengerTrain", "GoodsTrain". Also "AcceleratedPassengerTrain derives from "PassengerTrain".
Then I used dependency as u said.
- HighSpeedTrain---->Electrified
- PassengerTrain---->Normal, Electrified
- GoodsTrain---->Normal, Electrified
- AcceleratedPassengerTrain---->Electrified
But im not sure if it's true. Another problem; "AcceleratedPassengerTrain" should only use electrified rail. In my solution, I think it also supports normal rail because it inherits from "PassengerTrain". Please tell me what do you think about the design. Thanks for your help.
精彩评论