types - 设计模式 : Question about "Types"

标签 types design-patterns

谁能给我解释一下下面这一段是什么意思?这是“设计模式:可重用 OO 软件的元素”的片段

Part of an object's interface may be characterized by one type, and other parts by other types. Two objects of the same type need only share parts of their interfaces. Interfaces can contain other interfaces as subsets. - Design Patterns - Elements of Reusable OO software, pg 13

最佳答案

要理解这意味着什么,您首先需要记住 Gang of Four早在 1994 年就写了这本书,当时世界上绝大多数程序员都没有使用(也从未听说过)面向对象编程。

Gamma、Helm、Johnson 和 Vlissides 基本上都是在这里介绍接口(interface)的概念。这个想法是,一段与对象交互的代码并不真正需要了解底层实现是如何发生的,并且两个不同的对象可以具有相同的接口(interface)但具有不同的实现。今天,我们一直在使用 Java 和 Objective-C 中的接口(interface)来做到这一点。

但它们更进一步,暗示一个对象可能有多个接口(interface),一个来自一种类型(或接口(interface)),一个来自另一种。您可以使用 C++ 中的多重继承、Java 中的多个接口(interface)或仅使用相同的命名约定来明确地做到这一点。

关于types - 设计模式 : Question about "Types",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4581891/

相关文章:

Java 启动错误选择不包含主类型

python - 将类型指定为数字列表(整数和/或 float )?

linux - 我应该如何在后台运行我的 Golang 进程?

asp.net-mvc - 包装 IHttpActionResult - 通用解决方案

generics - Kotlin 中的通用 lambda 或函数值类型

c# - HashPasswordForStoringInConfigFile()的输出是什么格式,如何存储最好?

python - Pandas 中的 dtype ('O' ) 是什么?

javascript - 不会扰乱 eslint 的 javascript 实例化模式

c++ - 确保所有构造函数调用相同的函数 c++,设计模式

c# - 类似 Gmail 的标签系统