public claass OperatorFactory{ public static Operator createOperator(String operate){ Operation oper=null; swich(operate){ case"+": oper=new OperationAdd(); break; ... } return oper; } }
直接调用OperationFactory.createOperator("+")就可以创建一个OperationAdd对象。
OperatorFactory依赖Operation类,是一个生产Operation类的工厂。