Java與模式 - 面向對象的設計原則與設計模式

面向對象的設計原則
1)“開-閉”原則(Open-Closed Principle, 或者OCP)
Software entities should be open for extension, but closed for modification

2)里氏代換原則(Liskov Substitution Principle, 或者LSP)
如果對每一個類型爲T1的對象o1, 都有類型爲T2的對象o2, 使得以T1定義的所有程序P在所有的對象o1都代換成o2時, 程序P的行爲沒有變化,那麼類型T2是類型T1的子類型

3)依賴倒轉原則(Dependency Inversion Principle, 或者DIP)
Abstraction should not depend upon details. Details should depend upon abstractions

4)接口隔離原則(Interface Segregation Principle, 或者ISP)
使用多個專門的接口比使用單一的總接口要好

5)合成/聚合複用原則(Composition/Aggregation Reuse Principle, 或者CARP)
要儘量使用合成/聚合, 儘量不要使用繼承

6)迪米特法則(Law of Demeter, 或者LoD)
Least Knowledge Principle, LKP
Only talk to your immediate friends
Don't talk to strangers

設計模式
一、創建模式
1)簡單工廠模式(Simple Factory)


2)工廠方法模式(Factory Method)


3)抽象工廠模式(Abstract Factory)


4)單例模式(Singleton)


5)多例模式(Multiton)


6)建造模式(Builder)


7)原型模式(Prototype)


二、結構模式
1)適配器模式(Adapter)


2)缺省適配器模式(Default Adapter)


3)合成模式(Composite)


4)裝飾模式(Decorator)


5)代理模式(Proxy)


6)享元模式(Flyweight)


7)門面模式(Facade)


8)橋樑模式(Bridge)


三、行爲模式
1)不變模式(Immutable)

2)策略模式(Strategy)


3)模板方法模式(Template Method)


4)觀察者模式(Observer)


5)迭代子模式(Iterator)


6)責任鏈模式(Chain of Responsibility)


7)命令模式(Command)


8)備忘錄模式(Memento)


9)狀態模式(State)


10)訪問者模式(Visitor)


11)解釋器模式(Interpreter)


12)調停者模式(Mediator)

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章