【发布时间】:2016-09-18 21:22:32
【问题描述】:
我正在为 n 层应用程序建模域接口并准备接口 ICustomerRepository。 在里面我有很多签名,其中两个面临“相同签名”错误。
Customer GetCustomer(string guid, CustomerInformationLevel informationLevel
= CustomerInformationLevel.AccountInformation);
Customer GetCustomer(string firstName, string lastName, string middleName,
CustomerInformationLevel informationLevel
= CustomerInformationLevel.AccountInformation);
Customer GetCustomer(string email, CustomerInformationLevel informationLevel
= CustomerInformationLevel.AccountInformation);
与 string 'guid' 和 'email' 的签名冲突。我知道它为什么会发生,但不知道如何在正确的架构和设计原则的背景下避免它。
【问题讨论】:
-
也许使用类型
Guid作为参数guid? -
或者有称为
GetCustomerById、GetCustomerByName和GetCustomerByEmail的方法。 -
或者更确切地说使用 Email 类作为电子邮件,因为稍后在它自己的类中对其进行验证是有意义的。
-
string[] names对于第二个将是另一种方式。不同的方法名称虽然更清楚 -
这两种方法具有完全相同的签名。参数名称对方法签名没有贡献。因此,您不会通过使用不同的参数名称来获得不同的签名。
标签: c# web-services design-patterns n-tier-architecture