我有大约20个不同的服务,我必须向它们发送请求,它们需要稍微不同的一组标头。在
坏的遗留代码是这样的
row = db.query_for_service()
if row.type == 'foo1'
// add common headers to request
// add foo1 specific headers 1
// add foo1 specific header 2
// add foo1 specific header 3
else if row.type == 'foo2'
// add common headers to request
// add foo2 specific header 1
...
...
...
else if row.type == foo20
// add common headers to request
// add foo20 specific header 1
// add foo20 specific header 2
// ...
send_request()
重构它的最佳方法是什么?我考虑过一些可能在这里起作用的模式(策略、构建器),但我不太确定。在
我目前正在学习Java和Python,我想知道这两种语言的解决方案会有什么不同
就我个人而言,我要做的就是沿着这些思路。在
类似于伪java/python。地图上会预先填好你需要的东西,然后只需挑出你想要的并附上。在
你应该试试Command模式。在
伪代码如下:
并在客户机中使用此结构:
^{pr2}$等等
相关问题 更多 >
编程相关推荐