设计模式-目录

来源:互联网 发布:用什么软件看电影最好 编辑:程序博客网 时间:2024/05/21 10:26


MarkdownPhotos/master/CSDNBlogs/DesignPatterns/top.jpg

概述

什么是设计模式

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

为什么我们要学习设计模式

总体来说,正确地使用设计模式可以增强系统的健壮性,可扩展性。每种设计模式都有其独特的优点,每篇文章中都会对其进行说明。

相关词汇

GOF

说到设计模式,就不得不提GOF(Gang of Four)。他们分别是Erich Gamma、Richard Helm、Ralph Johnson 和 John Vlissides。他们在1995年出版了《Design Patterns: Elements of Reusable Object-Oriented Software》 。该书列举并描述了 23 种设计模式,堪称是讲解设计模式最好的一本书之一。

面向对象程序设计的六大原则

面向对象程序设计中,需要遵守的原则可总结为6个,这就是大名鼎鼎的六大原则。面向对象程序设计原则也是我们用于评价一个设计模式的重要指标之一。在设计模式中,很多设计模式都遵守了这些原则。

  • 单一职责原则(Single Responsibility Principle)
  • 里氏替换原则(Liskov Substitution Principle)
  • 依赖倒置原则(Dependence Inversion Principle)
  • 接口隔离原则(Interface Segregation Principle)
  • 迪米特法则(Law Of Demeter)
  • 开闭原则(Open Close Principle)

分类

根据设计模式的参考书《Design Patterns: Elements of Reusable Object-Oriented Software》 (中文译名:设计模式 - 可复用的面向对象软件元素) 中所提到的,总共有 23 种设计模式。这些模式可以分为三大类。

除了这23中设计模式之外,简单工厂模式(Simple Factory Pattern)也值得我们了解一下。

  • 创建型模式(Creational Patterns)
    • 工厂方法模式(Factory Pattern)
    • 抽象工厂模式(Abstract Factory Pattern)
    • 单例模式(Singleton Pattern)
    • 建造者模式(Builder Pattern)
    • 原型模式(Prototype Pattern)
  • 结构型模式(Structural Patterns)
    • 适配器模式(Adapter Pattern)
    • 桥接模式(Bridge Pattern)
    • 组合模式(Composite Pattern)
    • 装饰器模式(Decorator Pattern)
    • 外观模式(Facade Pattern)
    • 享元模式(Flyweight Pattern)
    • 代理模式(Proxy Pattern)
  • 行为型模式(Behavioral Patterns)
    • 责任链模式(Chain of Responsibility Pattern)
    • 命令模式(Command Pattern)
    • 解释器模式(Interpreter Pattern)
    • 迭代器模式(Iterator Pattern)
    • 中介者模式(Mediator Pattern)
    • 备忘录模式(Memento Pattern)
    • 观察者模式(Observer Pattern)
    • 状态模式(State Pattern)
    • 策略模式(Strategy Pattern)
    • 模板方法模式(Template Pattern)
    • 访问者模式(Visitor Pattern)

每一类设计模式学习完之后,对其进行总结:

  • 创建型模式总结
  • 结构型模式总结
  • 行为型模式总结
原创粉丝点击