标签:作用 1.7 idc rod pac 实现 dfa print list集合
public abstract class Factory { public final Product create(String owner) { Product product = createProduct(owner); register(product); return product; } public abstract Product createProduct(String owner); public abstract void register(Product product); }
public abstract class Product { public abstract void use(); }
public class IDCard extends Product { private String owner; public IDCard(String owner) { System.out.println("创建"+owner+"的ID卡"); this.owner=owner; } @Override public void use() { System.out.println("使用"+owner+"的ID卡"); } public String getOwner(){ return owner; } }
public class IDCardFactory extends Factory { List owners = new ArrayList<>(); @Override public Product createProduct(String owner) { return new IDCard(owner); } @Override public void register(Product product) { owners.add(((IDCard)product).getOwner()); } }
public class Main { public static void main(String[] args){ Factory factory = new IDCardFactory(); Product product1= factory.create("s1"); Product product2= factory.create("s2"); Product product3= factory.create("s3"); product1.use(); product2.use(); product3.use(); } }
标签:作用 1.7 idc rod pac 实现 dfa print list集合
原文地址:https://www.cnblogs.com/use-D/p/9563120.html