static void Main() { BaseOperator addop = GenOpFactory.GenOp("+"); addop.NumberA = 1; addop.NumberB = 2; Console.WriteLine(addop.OperateInt()); BaseOperator subOp = GenOpFactory.GenOp("-"); subOp.NumberA = 2; subOp.NumberB = 1; Console.WriteLine(subOp.OperateInt()); }
public static BaseOperator GenOp(string tag) { BaseOperator op = null; switch (tag) { case "+": op = new AddOp(); break; case "-": op = new SubOp(); break; } return(op); }