什么是设计模式:
设计模式是一组重复使用的代码设计经验总结,大多数人都知道、分类和编目。它提高了代码的可重用性,使代码编程真正具有工程性。
[En]
Design pattern is a set of code design experience summary that is repeatedly used, most people know, classified and cataloged. It improves the reusability of code and makes code programming truly engineering.
设计模式的由来
在 1994 年,由 Erich Gamma、Richard Helm、Ralph Johnson 和 John Vlissides 四人合著出版了一本名为 Design Patterns - Elements of Reusable Object-Oriented Software(中文译名:设计模式 - 可复用的面向对象软件元素) 的书,该书首次提到了软件开发中设计模式的概念。
他们合称GOF(四人帮,全拼 Gang of Four)。
设计模式的类型
设计模式共有23种,分为三大类:创建型模式,结构型模式和行为型模式.当然还有另类的设计模式:J2EE设计模式
设计模式的六大原则
1、开闭原则(Open Close Principle)
打开/关闭原则意味着它可以扩展,也可以修改。当程序需要扩展时,无法修改原始代码以实现热插拔效果。简而言之,它是为了使程序可扩展、易于维护和升级。为了达到这个效果,我们需要使用接口和抽象类,这将在稍后的具体设计中提到。
[En]
The open/close principle means that it is open to extension and closed to modification. When the program needs to be expanded, the original code cannot be modified to achieve a hot plug effect. In short, it is to make the program extensible, easy to maintain and upgrade. To achieve this effect, we need to use interfaces and abstract classes, which will be mentioned later in the specific design.
2、里氏代换原则(Liskov Substitution Principle)