I have a Fleet class that contains an array of vehicles (base class). Cars in an array are subclasses of vehicles: plains, trains, and cars. The array is private, but the Fleet class must offer a method to get to vehicles of a certain type.
Sort of:
class Fleet
{
private Vehicle[] _vehicles;
public ???? Get(????)
{
return ????
}
}
Fleet fleet = new Fleet("fleet.def");
Trains[] trains = fleet.Get(Trains);
Plains[] plains = fleet.Get<Plains>();
(I use arrays, but really any type of collection that can be repeated is fine.)
Now, as you can see, I absolutely do not know how to implement this. I am looking for an elegant solution for the Get method, efficiency is actually not a problem. Please also name the key methods used in the solution, so I can find them in my C # books ...
Thank!