首页 > 代码库 > Java—工厂模式

Java—工厂模式

工厂模式:public interface Cookie {    public abstract void run ();}public abstract class CookieFactory {        abstract Cookie create();}public class BearCookie implements Cookie{    public void run (){        System.out.println("正在制作小熊饼干");    }}public class NumberOneFactory extends CookieFactory{    Cookie create(){        return new BearCookie();    }}public class Test {    public static void main(String[] args) {        CookieFactory cf=new NumberOneFactory();        Cookie c=cf.create();        c.run();    }}

 

Java—工厂模式