工厂模式: 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(); } }
时间: 2024-11-03 22:35:16