标签:
类图:
1 public interface IFactory { 2 public Operation createOperation(); 3 }
1 public class AddOperationFactory implements IFactory { 2 3 @Override 4 public Operation createOperation() { 5 return new AddOperation(); 6 } 7 }
1 public class Client { 2 3 public static void main(String[] args) 4 { 5 IFactory addFactory = new AddOperationFactory(); 6 Operation add = addFactory.createOperation(); 7 add.setNumberA(1); 8 add.setNumberB(2); 9 System.out.println(add.getResult()); 10 } 11 }
图片引用自:《大话设计模式》-程杰
标签:
原文地址:http://www.cnblogs.com/gatsbydhn/p/4995940.html