两个接口的实例可以互相引用吗?

发布于 2024-12-03 11:58:03 字数 186 浏览 7 评论 0原文

使用 C#

Interface A,
Interface B,

Class AA:A
{

 public AA(A a)
{
 //...
}

}

Class BB:B
{

public BB(B b)
{
  //...
}

}

代码是否可以正常工作并且不会导致循环引用问题?

Using C#

Interface A,
Interface B,

Class AA:A
{

 public AA(A a)
{
 //...
}

}

Class BB:B
{

public BB(B b)
{
  //...
}

}

are the code works fine and not cause the circular reference problem?

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

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

发布评论

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

评论(1

年少掌心 2024-12-10 11:58:03

为什么不呢?除了语法之外,自相似结构在计算机科学中随处可见。考虑一棵二叉树:每个节点都有对另外两棵树的引用(由它们的根节点表示)。制作此类树的典型方法是使用对该类型的其他实例的两个引用而不是一个引用来构造类型。

更一般地说,类型系统中的循环与对象图中的循环不同。通常第一个是设计使然,但第二个有可能变成错误。

Why not? Syntax aside, self-similar structures appear all over computer science. Consider a binary tree: each node has a reference to two other trees (represented by their root nodes.) A typical way to make such a tree is a type that is constructed with not one, but two references to other instances of the type.

More generally, cycles in the type system are not the same as cycles in the object graph. Usually the first is by design, but the second has a way of turning into bugs..

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