I have to write a class called Vehicle
with many attributes (e.g. size, seats, color, ...) and also I have two more classes to write called Trunk
and Car
with their own attributes.
So I wrote it:
// Vehicle.cs
abstract public class Vehicle
{
public string Key { get; set; }
...
}
// Car.cs
public class Car : Vehicle
{
...
}
// Trunk.cs
public class Trunk : Vehicle
{
...
}
After that, I wrote an Interface:
// IVehicleRepository.cs
public interface IVehicleRepository
{
void Add(Vehicle item);
IEnumerable<Vehicle> GetAll();
Vehicle Find(string key);
Vehicle Remove(string key);
void Update(Vehicle item);
}
So I was thinking that I could use something like this:
// CarRepository.cs
public class CarRepository : IVehicleRepository
{
private static ConcurrentDictionary<string, Car> _cars =
new ConcurrentDictionary<string, Car>();
public CarRepository()
{
Add(new Car { seats = 5 });
}
public IEnumerable<Car> GetAll()
{
return _cars.Values;
}
// ... I implemented the other methods here
}
But, I got errors:
error CS0738: 'CarRepository' does not implement interface member 'IVehicleRepository.GetAll()'. 'CarRepository.GetAll()' cannot implement 'IVehicleRepository.GetAll()' because it does not have the matching return type of 'IEnumerable<'Vehicle>'.
So, how I can do it?