我暴露给用户的旧版界面是这样的:
public interface IReporter
{
void Write(int site, DateTime start, DateTime end);
}
现在我想替换函数中的参数如下:
public interface IReporter
{
void Write(int site, SiteLocalDateTime start, SiteLocalDateTime end);
}
我希望现有客户使用旧方法,新客户使用新方法。
关于如何通过公开单一接口(interface)来实现这一点有什么想法吗?
选项:
保持两个接口(interface)
IReporter
和IReporterNew : IReporter
现在,我所有的新实现都需要使用这两种方法。暴露两个接口(interface)是不可能的。
最佳答案
如果方法的实现在您这一端,您可以将接口(interface)合并为一个。然后用户可以决定使用哪个。 (最好将旧方法标记为过时,谢谢 3dd )
public interface IReporter
{
[Obsolete]
void Write(int site, DateTime start, DateTime end);
void Write(int site, SiteLocalDateTime start, SiteLocalDateTime end);
}
如果这不是您所追求的,您实际上应该对您的软件进行版本控制。一个版本供新客户使用,一个“旧版”版本供现有客户使用。最终您可以将老客户迁移到新版本。
您甚至可以创建 conversion between the two types如果知道实际的实现类型,但我不确定这在这种情况下是否有用。
此外,您的意思是使用 DateTimeOffset
而不是 SiteLocalDateTime
?
关于c# - 接口(interface)版本控制问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31673557/