我有这两个C#对象,它们公开了一些属性
class A{
prop1,prop2, prop3, producttype
}
class B{
prop10, prop11, prop12, prop13, productype
}根据产品类型的不同,在运行时,匹配算法会发生变化。例如,
if (A.productType =="ABC")
then match this logic, A.prop1 == B.prop10 && A.prop3 == B.prop12
if (A.productType=="DEF")
then match this logic A.pro1 == B.prop11
//and many more如何清晰地编写这样的逻辑并可重用?有没有我可以使用的设计模式?
发布于 2015-07-01 19:12:47
看一看Strategy Pattern。但是,您将无法绕过一些if/else块来选择正确的策略,除非您能够抽象出选择策略所依据的规则。
https://stackoverflow.com/questions/31147124
复制相似问题