【发布时间】:2017-07-09 21:10:48
【问题描述】:
我无法理解以下要求的实现:
- 创建一个接口类
Interface。 - 创建 n 个类
ImplementationN,以不同方式实现Interface。 - 创建一个新类
UsingInterface,它使用来自Interface的函数来定义自己的函数。 - 创建 n 个新类,允许使用在
UsingInterface中创建的函数,但通过ImplementationN类之一实现UsingInteface的方法使用的函数。
以下是我想出的解决方案:
【问题讨论】:
-
你不明白什么?这是Strategy Pattern。
-
我不确定如何在 Python 中实现此行为,但认为我已经在下面的示例中正确地做到了。感谢您提供反馈。
-
也许可以在Code Review 上发帖。
标签: python inheritance interface multiple-inheritance