我想这也是一个设计问题。当重写签名具有不同的签名类型时,是否可以从接口覆盖方法?C#接口 - 具有不同签名的工具
例如,让我们说,我想应该有两个不同的类以下内容:
interface IProtocolClient
{
void connect(Type1 t1, Type2 t2, Type3 t3);
}
有没有可能到impelemt的interfrace,但有不同的参数吗?
class A : IProtocolClient {
public void connect(Type1 t1, Type2 t2, Type3 t3) {}
}
class B : IProtocolClient {
public void connect(Type1 t1, Type2 t2, Type3 t3, Type4 t4) {}
}
或者我应该接近这个通过创建一个基类来代替,然后创建类B中的包装方法,如:
class B : IProtocolClient {
public void connect(Type1 t1, Type2 t2, Type3 t3, Type4 t4)
{
// do what is needed with t4 to customize and then ...
connect(t1,t2,t3);
}
public void connect(Type1 t1, Type2 t2, Type3 t3) {}
}
他们应该使用仿制药,而不是名单,如果这就是你所建议。 –
jlafay
2011-06-03 15:39:12
是的很多 – 2011-06-03 16:07:31