<p>特别是在单元测试中,我们使用这种“设计模式”,我称之为“从类级别获取类”</p>
<p>在框架测试.py公司名称:</p>
<pre><code>class FrameWorkHttpClient(object):
....
class FrameWorkTestCase(unittest.TestCase):
# Subclass can control the class which gets used in get_response()
HttpClient=FrameWorkHttpClient
def get_response(self, url):
client=self.HttpClient()
return client.get(url)
</code></pre>
<p>在我的测试.py公司名称:</p>
^{pr2}$
<p>方法<code>get_response()</code>从<code>self</code>获取类,而不是通过导入它。这样子类可以修改类并使用不同的<code>HttpClient</code>。在</p>
<p>这个(从类级别获取类)“设计模式”的名称是什么?在</p>
<p>这是“控制反转”还是“依赖注入”?在</p>