Cha*_*ert 1 c# design-patterns anti-patterns parameter-object
下面是一些使用参数类来包含Show()方法可能参数的代码.这个FooOption类中的值不是很相关.您可以通过查看Show()下面的实现来看到这一点.我知道这是错误的代码,但有没有与此相关的反模式?
class FooOptions {
public int? Id { get; set; }
public string BazContext { get; set; }
public int? BazId { get; set; }
}
class BarMgr {
public Bar Show(FooOptions options) {
if (options == null)
options = new FooOptions();
if (options.Id.HasValue)
return svc.GetBar(options.Id.Value);
if (!string.IsNullOrEmpty(options.BazContext) && options.BazId.HasValue)
return svc.GetBar(options.BazContext, options.BazId.Value);
return null;
}
}
Run Code Online (Sandbox Code Playgroud)
更新:我知道参数对象不是反模式.根据我的经验,参数对象属性是相关的.这是我试图找到的可能的反模式.设置所有三个属性是没有意义的.
| 归档时间: |
|
| 查看次数: |
358 次 |
| 最近记录: |