设计模式概述

Table of Contents

设计模式是解决某些具有相同模式的问题的一些固定套路,由 Eric Gamma、Richard Helm、Ralph Johnson、John Vlissides 等人整理成书1。并为常用的 23 种设计模式赋予形象的名字,这些名字为开发人员提供了一种共享的设计词汇和概念。

设计模式六大原则

总原则 — 开闭原则(Open Closed Principle)

  1. 单一职责原则(Single Reponsibility Principle)
  2. 里氏替换原则(Liskov Substitution Principle)
  3. 依赖倒置原则(Dependence Inversion Principle)
  4. 接口隔离原则(Interface Segregation Principle)
  5. 迪米特法则(最少知道原则)(Law of Demeter)
  6. 合成复用原则(Composite Reuse Principle)

设计模式的分类

根据设计模式的特点,可将这 23 种设计模式分为三大类。分别是:创建型设计模式、结构型设计模式、行为型设计模式。

  1. 创建型设计模式

    包括抽象工厂模式(Abstract Factory)、工厂方法模式(Factory Method)、单例模式(Singleton)、

  2. 结构型设计模式
  3. 行为型设计模式

Footnotes:

1

《设计模式:可复用面向对象软件的基础》

Date: 2024-03-11 Mon 19:45

Author: xueshumeng

Email: xue.shumeng@yahoo.com

Created: 2025-07-05 Sat 15:09