//單例模式 public class Singleton(){ private Singleton single=new Singleton(); private Singleton(){} public static Singleton getInstance(){ return single; } }
//工廠模式 public interface Fruit{} public class Apple implement Fruit{} public class Barana implement Fruit{} public class Pear implement Fruit{} public class factory{ public static Fruit getFruit(String type){ if(type.equals("apple")){ return new Apple(); } if(type.equals("barana")){ return new Barana(); } if(type.equals("pear")){ return new Pear(); } } }
這文值得一看: http://www.doc88.com/p-38771914275.html http://www.cnblogs.com/xuxm2007/archive/2010/11/05/1870108.html 1、expor
設計模式總結 之 創建型參考:http://blog.csdn.net/jason0539設計模式和原則 強烈推薦 http://blog.csdn.net/zhengzhb/article/category/926691總共有24中設計