标签:factor creat new void 工厂方法模式 main 客户 turn 区别
1.抽象产品类
public abstract class AbstractProduct { }
2.抽象工厂类
public abstract class AbstractFactory { public abstract AbstractProduct createProduct(); }
3.具体产品类
public class Product extends AbstractProduct { }
4.具体工厂类
public class Factory extends AbstractFactory { @Override public AbstractProduct createProduct() { // TODO Auto-generated method stub return new Product(); } }
5.客户程序
public class Client { //工厂方法,与抽象工厂的最主要区别可能就在此,单个对象的维度 public AbstractProduct getProduct(AbstractFactory factory){ return factory.createProduct(); } }
6.应用
public class App { public static void main(String[] args) { Client client=new Client(); AbstractProduct product = client.getProduct(new Factory()); } }
标签:factor creat new void 工厂方法模式 main 客户 turn 区别
原文地址:http://www.cnblogs.com/Niel-3/p/7466196.html