标签:
//抽象工厂 public interface ISwordFactory { public AbstractSword createSword(); }
//抽象产品 public abstract class AbstractSword { private String name; public String getName() { return name; } public void setName(String name) { this.name = name; } }
//具体工厂 public class CaoCao implements ISwordFactory { public AbstractSword createSword() { return new QiXingSword(); } }
//具体产品 public class BaXingSword extends AbstractSword { public BaXingSword() { this.setName("八星宝刀"); } }
//Main public static void main(String[] args) { // ISwordFactory factory = new CaoCao(); ISwordFactory factory = new CaoCao2(); //AbstractSword sword = factory.createSword(); AbstractSword sword = factory.createSword(); System.out.println(sword.getName()); }
标签:
原文地址:http://www.cnblogs.com/jin12/p/5505904.html