I am trying to implement (C#) an interface method in a class, returning a derived type instead of the base type as defined in the interface:
interface IFacto
There are 2 ways to accomplish this. You can either use generics or explicitly implement interface members.
Generics
interface IFactory where T: BaseCar
{
T GetCar();
}
class MyFactory : IFactory
{
MyCar GetCar()
{
}
}
Explicitly implemented members
interface IFactory
{
BaseCar GetCar();
}
class MyFactory : IFactory
{
BaseCar IFactory.GetCar()
{
return GetCar();
}
MyCar GetCar()
{
}
}