装饰的功能@staticmethod和装饰的功能有什么区别@classmethod?
特别是在单元测试中,我们使用这种"设计模式",我称之为"从班级获取课程"
framworktest.py:
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)
Run Code Online (Sandbox Code Playgroud)
mytest.py:
class MyHttpClient(FrameWorkHttpClient):
....
class MyTestCase(FrameWorkTestCase):
HttpClient=MyHttpClient
def test_something(self):
response=self.get_response()
...
Run Code Online (Sandbox Code Playgroud)
该方法不是通过导入来get_response()获取类self.这样子类可以修改类并使用不同的类HttpClient.
这个名称是什么(从班级获得类)"设计模式"?
这是"控制反转"还是"依赖注入"?
python inheritance design-patterns dependency-injection inversion-of-control