Skip to main content
 首页 » 编程设计

c#之如何区分逻辑上命名相同的命令模式中的包装层

2024年02月23日15jpfss

我有这个界面...

public interface ICheckThatDocumentExistsCommand 
{ 
   bool Execute( string userId, string docId ); 
} 

在实现中,我只想验证两个id,如果有效,返回另一个接口(interface)的结果...

public interface ICheckThatDocumentExistsCommand 
{ 
   bool Execute( UserId userId, DocumentId docId ); 
} 

我想在同一个业务域程序集中定义接口(interface),但我很难决定如何区分这两个(或更多)层。从逻辑上讲,我认为它们的名称即使不相同也很相似,所以我不能将它们放在同一个命名空间下。我是否通过命名空间分开? “验证”命名空间和“其他”命名空间?或者我是否将已经冗长的名称扩展为有点荒谬的东西,例如...

public interface IValidateIdsAndThenCheckThatDocumentExistsCommand 

随着我保持函数的小型化和单一用途,我看到这种情况越来越多。

请您参考如下方法:

好吧,它的实现类正在弄清楚如何处理参数....所以为什么不让实现类确定和验证类型....

public interface ICheckThatDocumentExistsCommand 
{ 
  bool Execute<t1,t2>(t1 userID, t2 docId); 
}