在 python 上下文中,组合和外观是相同的东西。我知道外观设计模式的用途,但只是想确保我可以调用我的类,它实现了外观,组合?
我可以对 mixin 类说同样的话,还是它只是一个不同的野兽,更接近多重继承并解决一些比外观以外的其他问题?
我们能否松散地将 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/