设计模式(一)——概述(Overview)

最近在上课和考试都遇到很多设计模式方面的问题,所以决定在网上学习一下相关的知识,免得以后碰到又不会了。

一、设计模式

设计模式(Design pattern)是一套被反复使用、多数人知晓的、经过分类编目的、代码设计经验的总结。使用设计模式是为了可重用代码、让代码更容易被他人理解、保证代码可靠性。 毫无疑问,设计模式于己于他人于系统都是多赢的;设计模式使代码编制真正工程化;设计模式是软件工程的基石脉络,如同大厦的结构一样。

二、设计原则

开闭原则(Open Closed Principle):S oftware entities (classes, modules, functions, etc.) should be open for extension, but closed for modification.
里氏代换原则(Liskov Substitution Principle):In a computer program, if S is a subtype of T, then objects of type T may be replaced with objects of type S (i.e., objects of type S may substitute objects of type T) without altering any of the desirable properties of that program (correctness, task performed, etc.).
依赖倒转原则(Dependency Inversion Principle):The conventional dependency relationships established from high-level, policy-setting modules to low-level, dependency modules are inverted (i.e. reversed), thus rendering high-level modules independent of the low-level module implementation details.
接口隔离原则(Interface Segregation Principle):No client should be forced to depend on methods it does not use.
合成/聚合复用原则(Composite/Aggregate Reuse Principle):Composite/Aggregate Reuse Principle(CARP) or Composite Reuse Principle(CRP) which is using existed object in new object to make it a part of new object;To reuse already existed function the new object delegate to those obgect.
最小知识原则(Principle of Least Knowledge):A given object should assume as little as possible about the structure or properties of anything else (including its subcomponents), in accordance with the principle of "information hiding".
三、基本模式

创建型模式:单例模式、抽象工厂模式、建造者模式、工厂模式、原型模式。

结构型模式:适配器模式、桥接模式、装饰模式、组合模式、外观模式、享元模式、代理模式。

行为型模式:模版方法模式、命令模式、迭代器模式、观察者模式、中介者模式、备忘录模式、解释器模式、状态模式、策略模式、职责链模式、访问者模式。



你可能感兴趣的:(设计模式,设计模式)