經常使用的設計模式有哪些,做用是什麼
設計模式一共23種,經常使用的設計模式有:html
單例模式的懶漢和餓漢模式你瞭解嗎
懶漢模式:太懶了,第一次用的時候纔去實例化,適合使用量較小的狀況。算法
public class Singleton { private Singleton() { } private static Singleton singleton = null; public static Singleton getInstance() { if (singleton == null) { singleton = new Singleton(); } return singleton; } }
餓漢模式:很勤快,類定義的時候就實例化了。線程安全的,適合訪問量比較大的狀況。設計模式
public class Singleton { private Singleton(){ } private static final Singleton singleton = new Singleton(); public static Singleton getInstance(){ return singleton; } }
Spring框架用到了哪些設計模式安全
你怎麼選擇合適的設計模式
考慮設計模式怎麼解決問題,找出與使用者問題相關的模式,研究模式如何相互關聯,考慮設計中那些是可變的,儘量實現強內聚,鬆耦合。框架
http://www.javashuo.com/article/p-gvbnwude-ka.html
http://c.biancheng.net/design_pattern/
http://www.javashuo.com/article/p-vnqbejmv-hc.htmlspa