今天我为基于运营商的Expression创建了一个工厂。 但是当我创建我的工厂时,它对比较值有一定的依赖性。
这是我的代码
public LambdaExpression GetPredicate(FieldType fieldType, GigFilterOption value)
{
switch (fieldType)
{
case FieldType.PriceNumeric :
return new OperatorFactory( Convert.ToDecimal(value.LowerLimit), Convert.ToDecimal(value.UpperLimit)).GetOperator((Operator)value.Operator).Apply<YayNinja.DAL.Task>("Price");
break;
case FieldType.TimePeriod :
return new OperatorFactory(Convert.ToDecimal(value.LowerLimit), Convert.ToDecimal(value.UpperLimit)).GetOperator((Operator)value.Operator).Apply<YayNinja.DAL.Task>("Duration");
break;
case FieldType.CheckBox:
case FieldType.Radio:
return new OperatorFactory(value.LowerLimit, value.UpperLimit).GetOperator((Operator)value.Operator).Apply<TaskField>("Value");
break;
default :
throw new NotImplementedException();
};
}
这是我的运营商工厂。
public class OperatorFactory : IOperatoFactory
{
private object lowerLimit;
private object upperLimit;
public OperatorFactory(object _lowerLimit, object _upperLimit) //**here you see dependency of value that i need for comparsion.**
{
lowerLimit = _lowerLimit;
upperLimit = _upperLimit;
}
public IOperatorPredicate GetOperator(Operator @operator)
{
IOperatorPredicate operatorPredicate = null;
switch (@operator)
{
case Operator.Equal:
operatorPredicate = new EqualToPredicate(lowerLimit);
break;
case Operator.GreaterThan:
operatorPredicate = new GreaterThanPredicate(lowerLimit);
break;
case Operator.GreaterThanOrEqual:
operatorPredicate = new GreaterThanEqualPerdicate(lowerLimit);
break;
case Operator.LessThan:
operatorPredicate = new LessThanPredicate(lowerLimit);
break;
case Operator.LessThanOrEqual:
operatorPredicate = new LessThanEqualPredicate(lowerLimit);
break;
case Operator.Between:
operatorPredicate = new BetweenPredicate(lowerLimit,upperLimit);
break;
default:
throw new NotImplementedException();
}
return operatorPredicate;
}
}
我确信工厂模式是创建者模式,它只创建没有任何依赖的对象。
请指导我这个主题