c# - 调用设计模式的方法

标签 c# java design-patterns

我正在对应用程序进行代码审查。我正在寻找一种设计模式,可以消除多次调用一个方法的重复,例如

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/

相关文章:

c# - 重置光标.Clip

c# - 一个重构代码如何参与嵌套使用?

java - JPA - 将实体的字段映射到数据库函数结果

java - 为什么在 Android 上使用 db.exec() 时不需要捕获 SQLExecption?

C# 枚举与数据驱动列表

c# - 如何在 ASP.NET MVC3 中上传和读取 CSV 文件

C# 如何将错误追加到 1 个消息框中?

java - Mac OSX Java 终端版本不正确

javascript - Object.create 和引用属性

php - 在服务层或模型中的何处放置插入和获取查询逻辑?