This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TrainLine | |
{ | |
private readonly List<Station> stations = new List<Station>(); | |
public IEnumerable<Station> Stations | |
{ | |
get { return stations; } | |
} | |
public void AddStation(Station station) | |
{ | |
stations.Add(station); | |
station.AddTrainLine(this); | |
} | |
public void RemoveStation(Station station) | |
{ | |
stations.Remove(station); | |
station.RemoveTrainLine(this); | |
} | |
} | |
public class Station | |
{ | |
private readonly List<TrainLine> trainLines = new List<TrainLine>(); | |
public IEnumerable<TrainLine> TrainLines | |
{ | |
get { return trainLines; } | |
} | |
public void AddTrainLine(TrainLine trainLine) | |
{ | |
trainLines.Add(trainLine); | |
} | |
public void RemoveTrainLine(TrainLine trainLine) | |
{ | |
trainLines.Remove(trainLine); | |
trainLine.RemoveStation(this); | |
} | |
} |
A linked list would be a more logical representation of stations for a train line but for this example we’re using a list.
No comments:
Post a Comment