【发布时间】:2012-03-14 00:46:48
【问题描述】:
我有以下类和接口。我想基本上冻结 IOld 接口(将被弃用)并强制用户使用 INew 接口,该接口将包含与 IOld 相同的方法。然而,INew 方法 Meth3 表示与 IOld Meth2 相同的功能,但返回类型不同,为了更好地区分它们,我认为这种设计是合适的。我的问题是,这被认为是良好的编码实践吗?
注意:IOld 和 INew 位于单独的程序集中。 NewClass 不能以任何方式引用 IOld,因为它将作为可远程 (MarshalByRef) 对象公开,客户端将通过 INew 接口连接到该对象。我不希望新客户端引用 IOld 程序集。
public interface IOld
{
void Meth1();
double Meth2(int input);
}
public interface INew
{
void Meth1();
float Meth3(int input);
}
public abstract class BaseClass
{
public virtual void Meth1()
{
}
public virtual double Meth2(int input)
{
throw new NotImplementedException();
}
}
public class OldClass
:
BaseClass,
IOld
{
public override double Meth2(int input)
{
return 0;
}
}
public class NewClass
:
BaseClass,
INew
{
public float Meth3(int input)
{
return 0;
}
}
【问题讨论】:
标签: c# .net interface abstract-class