z***e 发帖数: 5393 | 1 (回家用汉语补充了一下,方便阅读)
for example, we have a program running with arguments:
(简单说就是像下面这种要带很多参数的程序,程序里面要根据action参数进行不同的动作,比如可能是网络连接,可能是打字,可能是写文件,然后每个动作都有自己的特定参数从命令行里面读取,那么,怎么设计class或者whatever来漂亮处理这些参数?)
myprogram -action xxxx -name xxxx -password xxxx -ipaddress xxxx -portnumber
xxxx [....]
Inside the program, we have different actions, and each action has its own
parameters from the commandline arguments. For example, action1 may need
ipaddress and portnumber, action2 may need username and password, | s******e 发帖数: 431 | 2 Wrapping everything in a configuration class and pass the pointer to the
function is okay. And when a new parameter needs to be added, the interface
doesn't need to be changed.
However, it is also increasing the complexity for users to use the function
(action). It is hard to know how many parameters are required to do this
action. |
|