在这种情况下,我会定义你的抽象类的通用实现,这样你就会得到这样的东西:
public abstract class EngineBase<T>
{
public abstract void Refuel(T parameters);
}
然后你的实现看起来像这样:
public class ElectricEngine : EngineBase<ElectricParameters>
{
public override void Refuel(ElectricParameters parameters) { }
}
或者,您可以定义一个接口,并将特定的实现传递给您的方法:
public abstract class EngineBase
{
public abstract void Refuel(IRefuelParameters parameters);
}
然后你的实现看起来像这样:
public class ElectricEngine : EngineBase
{
public override void Refuel(IRefuelParameters parameters)
{
if(!(parameters is ElectricParameters))
throw ApplicationException("Not the right params!");
ElectricParameters rightParams = parameters as ElectricParameters;
}
}