我正在对一个应用程序进行代码审查。我正在寻找一种设计模式,可以消除像一样多次调用一个方法的重复
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)