我正在对应用程序进行代码审查。我正在寻找一种设计模式,可以消除多次调用一个方法的重复,例如
UpdateAddress(InstallType.word, name, age);
UpdateAddress(InstallType.excel, name, age);
UpdateAddress(InstallType.powerpoint, name, age);
因此,在上面的示例中,UpdateAddress 方法使用不同的参数调用多次。有什么好的办法吗?
最佳答案
for (InstallType t: InstallType.values) {
UpdateAddress(t, name, age);
}
但实际上 UpdateAddress 应该称为 updateAddress。
如果您能够修改 UpdateAddress,那么您可以将该方法更改为:
void updateAddress(Collection<InstallType> types, name, age)
或
void updateAddress(name, age, InstallType... types)
关于c# - 调用设计模式的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20544990/