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();
    }
}

 

posted @ 2014-09-12 22:59  shelly双鱼座  阅读(125)  评论(0编辑  收藏  举报