继承是一个“is-a”的过程。关系;总结“界面”的好方法是什么?关系? ——总结其他关系?

发布于 2024-11-28 02:19:46 字数 207 浏览 2 评论 0原文

标题:继承是一种“is-a”关系;总结“接口”关系的好方法是什么?

另外,我认为拥有一个简单关系的存储库来帮助人们正确看待事物会很好。我对编程相当陌生,所以我不确定是否真的有足够的“关系”来保证这个愿望——但如果有的话,这可能是一个很好的起点。

  • 继承=“is-a”
  • 组合=“has-a”
  • 接口实现=?...

Title: inheritance is an 'is-a' relationship; What is a good way to summarize the 'interface' relationship?

Also, I think it would be nice to have a repository of simple relationships to help people put things in perspective. I'm fairly new to programming so I'm not sure if there's really enough 'relationships' to warrant this aspiration-- but if there is, this may be a good place to start.

  • inheritance = "is-a"
  • composition = "has-a"
  • interface implementation = ?...

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

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

发布评论

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

评论(5

街角卖回忆 2024-12-05 02:19:46

接口实现 = "can-do"

接口通常代表您可以在类中实现的一种能力,例如在 .NET 中,IEnumerable 接口用于您可以枚举的类,并且 IComparable 用于可以比较的类。

Interface implementation = "can-do"

An interface usually represents one ability that you can implement in a class, for example in .NET the IEnumerable interface is used for classes that you can enumerate, and IComparable for classes that you can compare.

调妓 2024-12-05 02:19:46

为什么不只是“实现一个”?我想我不确定你在开车的目的是什么。

why not just "implements a"? guess I'm not sure what you're driving at.

独享拥抱 2024-12-05 02:19:46

您的谓词 is-a 和 has-a 描述了不同类型之间的结构关系。从这个意义上说,接口也应该有 is-a。

然而,还有更多可能的分类法和更多的 oop 关键概念:

  • 接口是每个实现者履行(承诺)的契约。
  • 对象之间的连接不仅可以使用组合来建立,还可以通过将对象传递给方法(uses-a)或涉及某种消息传递(notify-of)来建立。
  • 继承的目的不仅是通过不同地实现基类方法来实现多态(as-a),而且还可以添加新的功能(属性、方法)-(extends-a)。
  • OOP 应用程序中对象的角色可以分为管理 a、创建 a、访问 a、替代 a 等

Your predicates is-a and has-a describe the structural relation between different types. In that sense, an interface should also get the is-a.

However, there are more possible taxonomies and also more oop key concepts:

  • An interface is a contract that each implementor fulfils (promises-to).
  • Connection between objects can be established not only using composition but also by passing objects to methods (uses-a) or involving kind of messaging (notifies-of).
  • The purpose of inheritance is not only polymorphy (as-a) by differently implementing the base class methods but also to add new functionality (properties, methods) - (extends-a).
  • The role of objects in an OOP application may be classified with manages-a, creates-a, visits-a, substitutes-a, etc.
  • ...
白龙吟 2024-12-05 02:19:46

也许是“as-a”或“like-a”:暗示它具有某些属性/能力,但并非直接派生自。

Maybe "as-a" or "like-a": Implying that it has some properties/abilities but isn't directly derived from.

梦回旧景 2024-12-05 02:19:46

界面是一种“适合”的关系。

想想墙上的电源插座。这是您与电网的接口。您可能有许多共享此类接口的对象(即它们都“适合”套接字)。

其他国家有不同的界面,以及将“适合”这些特定方案的不同对象集。

Interface is a "fits-into" relationship.

Think about the electrical socket in your wall. That is your interface to the electrical grid. You may have many objects that share such an interface (i.e. they all "fit-into" the socket).

Other countries have different interfaces, along with differenct sets of objects which will "fit-into" those particular schemes.

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