我有一个代表请求的类。我有一组非常具体的请求,例如“I-95”,“P-22”等,它们执行不同的功能并由控制器类调用。这样做的最佳方法是什么,以便人们可以轻松地在路上添加更多请求?
我现在有这样的事情:
class Requests:
def __init__(self):
self.types = [
'I-95',
'P-22',
...
]
def generate_request(self,type, Data):
# Here I would call the appropriate case for the type, e.g. P-22
请求案例将在其自己的单独文件中,如下所示:
class P-22:
# Members
def __init__(self, Data):
# Set data members
def request(self):
# Submit request
我可以在控制器中创建一个请求
f = Requests()
f.generate_request('RC75')
我正在努力寻找尽可能干净且易于扩展的东西。谢谢!