更改接口属性类型是重大更改吗?

发布于 2025-01-17 03:27:45 字数 454 浏览 1 评论 0原文

这是一个重大的界面更改吗?如果是这样,为什么? (不是家庭作业,只是想确保其他客户端不会因此更改而中断)

当前接口:

public interface MyInterface
{
     IPropertyInterfaceOld Propery1 {get; set;}
}

public interface IPropertyInterfaceOld
{
}

建议接口:

public interface MyInterface
{
     IPropertyInterfaceNew  Propery1 {get; set;}
}

public interface IPropertyInterfaceOld
{
}

public interface IPropertyInterfaceNew : IPropertyInterfaceOld
{
}

Is this a breaking interface change? If so, why? (Not a homework assignment just trying to make sure other clients aren't broken with this change)

Current interfaces:

public interface MyInterface
{
     IPropertyInterfaceOld Propery1 {get; set;}
}

public interface IPropertyInterfaceOld
{
}

Proposed interfaces:

public interface MyInterface
{
     IPropertyInterfaceNew  Propery1 {get; set;}
}

public interface IPropertyInterfaceOld
{
}

public interface IPropertyInterfaceNew : IPropertyInterfaceOld
{
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

躲猫猫 2025-01-24 03:27:45

是的,这绝对是一个突破性的改变。

如果该属性是读/写的,则更改会破坏此代码:

MyInterface x = new MyImplementation();
IPropertyInterfaceOld y = null;
x.Propery1 = y;

即使该属性是只读的,也请考虑此类:

public class Implementation : MyInterface
{
    public IPropertyInterfaceOld Propery1 => null;
}

该实现会被您的更改破坏。您可能已经更改了项目中声明接口的所有实现,但任何其他实现现在都将被破坏。

(正如评论中所述,这也是一个二进制重大更改。)

Yes, that's absolutely a breaking change.

If the property is read/write, then the change breaks this code:

MyInterface x = new MyImplementation();
IPropertyInterfaceOld y = null;
x.Propery1 = y;

Even if the property is read-only, consider this class:

public class Implementation : MyInterface
{
    public IPropertyInterfaceOld Propery1 => null;
}

That implementation is broken by your change. You may have changed all the implementations in the project that declares the interface, but any other implementations will now be broken.

(It's also a binary breaking change as noted in comments.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文