Giter Club home page Giter Club logo

design-pattern's Introduction

经典设计模式Design Pattern,不同语言实现

  • 包括23种经典设计模式不同语言详解,结合实际场景,详细注释说明。每一行代码都经过检验,确保可靠。
  • 采用流行的语言,包括C/Java/JavaScript/Python/TypeScript/Go等,尊重语言特性。
  • 包含各种架构与设计**,不断完善和补充,打造编程**与架构设计的资源库。

设计模式结构图

设计模式源码

创建型

结构型

行为型

面向对象设计原则

1. 开闭原则(Open Closed Principle,OCP)

  • 对扩展开放,对修改关闭。希望程序扩展功能的时候,通过开放的接口来实现,而不是修改代码。例子 | 反例

2. 单一职责原则(Single Responsibility Principle,缩写为SRP)

  • 对一个类来说的,职责应该单一,只做一件或一类具体的事情。 例子 | 反例

3. 依赖倒置(也叫依赖反转)原则(Dependency inversion principle,DIP)

  • 是开闭原则的基础。指针对接口编程,高层模块不应该依赖低层模块,二者都依赖于抽象而不依赖于具体实现编程。例子 | 反例

4. 接口隔离原则(Interface Segregation Principle, 简称ISP)

  • 一个类对另一个类的依赖应该建立在最小的接口上,不依赖不需要的接口。尽量强调降低依赖,降低耦合。例子 | 反例

5. 组合/聚合复用原则(Composite/Aggregate Reuse Principle,CARP)

  • 写代码会涉及到代码复用,尽量使用组合而少使用继承。大多数情况下组合可以替代继承。例子 | 反例

6. 迪米特法则(Law of Demeter,LoD)

  • 又称最少知道原则,一个实体应当尽量少地与其他实体之间发生相互作用,使得系统功能模块相对独立。例子 | 反例

7. 里氏代换原则(Liskov Substitution Principle,LSP)

  • 任何父类出现的地方,子类也可以出现。子类可以实现父类的抽象方法,但不能覆盖父类的非抽象方法。例子 | 反例

编程设计**

Contact 联系

欢迎共建 Welcome to join

design-pattern's People

Contributors

jarry avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.