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)

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