设计模式概述(Design patern)

概述

是一套被反复使用、多数人知晓的、经过分类编目的、代码设计经验的总结。使用设计模式是为了可重用代码、让代码更容易被他人理解、保证代码可靠性。
设计模式和具体的语言无关,学习设计模式就是要建立面向对象的思想,尽可能的面向接口编程,低耦合,高内聚是设计的程序可复用。

Java中的设计模式是一些通用的解决方案,用于解决软件设计中常见的问题。这些设计模式提供了一种在软件设计中复用的方法,使得开发人员能够更加灵活和高效地解决问题。这些设计模式可以帮助开发人员编写更加可维护、可扩展和可重用的代码。

GOF

设计模式GOF的全称是“Gang of Four”,指的是四位作者:Erich Gamma、Richard Helm、Ralph Johnson和Johnvlissh。
他们在1994年出版了《Design Patterns: Elements of Reusable Object-Oriented Software》一书,书中系统性地介绍了23种经典的设计模式。这些设计模式被广泛应用于软件开发中,帮助开发者解决常见的设计问题。

分类

设计模式(GOF)分为三种类型,共23类。
一、创建型模式:

​ 单例模式、抽象工厂模式、建造者模式、工厂模式、原型模式。(5个)

二、结构型模式:

​ 适配器模式、桥接模式、装饰模式、组合模式、外观模式、享元模式、代理模式。(7个)

三、行为型模式:

​ 模版方法模式、命令模式、迭代器模式、观察者模式、中介者模式、备忘录模式、解释器模式、状态模式、策略模式、职责链模式、访问者模式。(11个)

常见的设计模式包括:

一、创建者模式

  • (1)单例模式 (Singleton Pattern)
  • (2)工厂模式(Factory Pattern)
    • 简单工厂模式
    • 工厂方法模式
    • 抽象工厂模式
  • (3)建造者模式 (Builder Pattern)
  • (4)原型模式(Prototype Pattern)

二、结构型模式

  • (1)适配器模式 (Adapter Pattern)
  • (2)装饰者模式(Decorator Pattern)//IO相关涉及 一层套一层
  • 桥接模式(Bridge Pattern)
  • 组合模式(Composite Pattern)
  • 外观模式(Facade Pattern)
  • 享元模式(Flyweight Pattern)
  • 代理模式(Proxy Pattern)

三、行为型模式

  • 观察者模式(Observer Pattern)

  • 策略模式(Strategy Pattern)

    • if(if(else)):rxjava if嵌套(过滤)
  • 模板方法模式(Template Method Pattern)

  • 迭代器模式(Iterator Pattern)

  • 命令模式(Command Pattern)

  • 备忘录模式(Memento Pattern)

  • 状态模式(State Pattern)

  • 责任链模式(Chain of Responsibility Pattern)

  • 访问者模式(Visitor Pattern)

  • 中介者模式(Mediator Pattern)

  • 解释器模式(Interpreter Pattern)

等待超时模式

Donate
  • Copyright: Copyright is owned by the author. For commercial reprints, please contact the author for authorization. For non-commercial reprints, please indicate the source.

扫一扫,分享到微信

微信分享二维码
  • Copyrights © 2023-2025 Annie
  • Visitors: | Views:

嘿嘿 请我吃小蛋糕吧~

支付宝
微信