设计模式学习笔记——概念

设计模式(Design pattern)代表了最佳的实践,软件开发人员在软件开发过程中面临的一般问题的解决方案。

Design patterns represent best practices and solutions to common problems faced by software developers in the process of software development.

设计模式是一套被反复使用的、多数人知晓的、经过分类编目的、代码设计经验的总结。

Design patterns are a set of repeated use, most people know, classification and cataloguing, code design experience summary.

使用设计模式是为了重用代码、让代码更容易被他人理解、保证代码可靠性。

Design patterns are used to reuse code, make it easier for others to understand, and ensure code reliability.

项目中合理地运用设计模式可以完美地解决很多问题,每种模式在现实中都有相应的原理来与之对应,每种模式都描述了一个在我们周围不断重复发生的问题,以及该问题的核心解决方案,这也是设计模式能被广泛应用的原因。

Reasonable use of design patterns in projects can solve many problems perfectly. Each pattern has corresponding principles in reality. Each pattern describes a problem that recurs around us and the core solution of the problem. This is also the reason why design patterns can be widely used.

为什么要提倡Design Pattern?根本原因是为了代码复用,增加可维护性

Why advocate Design Pattern? The fundamental reason is to reuse code and increase maintainability.

面向对象有几个原则:

Object-oriented has several principles:

  • 单一职责原则(Single Responsiblity Principle SRP)
  • 开闭原则(Open Closed Principle,OCP)
  • 里氏代换原则(Liskov Substitution Principle,LSP)
  • 依赖倒转原则(Dependency Inversion Principle,DIP)
  • 接口隔离原则(Interface Segregation Principle,ISP)
  • 合成/聚合复用原则(Composite/Aggregate Reuse Principle,CARP)
  • 最小知识原则(Principle of Least Knowledge,PLK,也叫迪米特法则)

设计模式使人们可以更加简单方便地复用成功的设计和体系结构。

Design patterns make it easier to reuse successful designs and architectures.

设计模式分为三种类型,共23种:

Design patterns fall into three categories,there are 23 kinds:
创建型模式(Creative mode):

  • 单例模式(Singleton Pattern)
  • 抽象工厂模式(Abstract Factory Pattern)
  • 建造者模式(Builder Pattern)
  • 工厂模式(Factory Pattern)
  • 原型模式(Archetypal Pattern)


结构型模式(Structural pattern):

  • 适配器模式(Adapter Pattern)
  • 桥接模式(Bridging Pattern)
  • 装饰模式(Decoration Pattern)
  • 组合模式(Combination Pattern)
  • 外观模式(Appearance Pattern)
  • 享元模式(Flyweight Pattern)
  • 代理模式(Proxy Pattern)


行为型模式(Behavioral patterns):

  • 模版方法模式(Template Method Pattern)
  • 命令模式(Command Pattern)
  • 迭代器模式(Iterator Pattern)
  • 观察者模式(Observer Pattern)
  • 中介者模式(Intermediary Pattern)
  • 备忘录模式(Memento Pattern)
  • 解释器模式(Interpreter Pattern)
  • 状态模式(State Pattern)
  • 策略模式(Strategy Pattern)
  • 职责链模式(Responsibility Chain Pattern)
  • 访问者模式(Visitor Pattern)
【微信公众号:Stephen】一个毕业三年后自学 Java 入行的程序员。
原文地址:https://www.cnblogs.com/stephen-java/p/10533920.html