python - python 中的组合和外观是同一件事吗?

标签 python multiple-inheritance mixins composition facade

  1. 在 python 上下文中,组合和外观是相同的东西。我知道外观设计模式的用途,但只是想确保我可以调用我的类,它实现了外观,组合?

  2. 我可以对 mixin 类说同样的话,还是它只是一个不同的野兽,更接近多重继承并解决一些比外观以外的其他问题?

  3. 我们能否松散地将 Python 中的组合称为 Java 中的接口(interface),否则这种说法完全不合适。

PS:我希望我的应用程序能够向客户端提供标准接口(interface),但随着我们获得更多的开发带宽,内部的确切实现将不断变化。由于客户将使用此类进行进一步开发,因此我不希望在我们在实现方面进行任何更改时破坏他们的代码。我想在开始项目之前解决我的术语困惑问题。

最佳答案

如上所述:

Composition is when one class contains members that are instances of other classes. The term Facade usually means that you are encapsulating a lot of logic behind the public members of a class. So notice that you can have composition without a Facade, if the composition members are all public. I won't get into the merit of a Facade without composition being valid, because that's a semantics labyrinth. BTW composition and interfaces are two different beasts, even if consider only Java or only Python.

关于python - python 中的组合和外观是同一件事吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18905550/

相关文章:

python - JSON 网站响应到 Python 字典

python - 使用 OpenCV dense SIFT 查找图像之间的匹配

javascript - 是否可以使用网页作为用 python 编写的程序的用户界面,在本地运行,无需 Web 服务器?

sass - SCSS 中的 & 符号和混入

python - PicklingError 中的多重处理结果

c++ - 使用一个实现其他类方法的类方法以及它自己的类方法

java - 如何在 Java 中建模 Can-Be-A 关系?

c++ - 对象层次结构的 "Implementation"- "the easiest way"或如何避免虚拟继承?

python - 可以使用 MRO 来覆盖混入吗?

python - PyQt5:派生 QWidget 类中带有元类的 Mixin 的问题