GithubHelp home page GithubHelp logo

lilin-lab / go-design-pattern Goto Github PK

View Code? Open in Web Editor NEW

This project forked from waynewyang/go-design-pattern

0.0 0.0 0.0 61 KB

go的设计模式实例

License: GNU General Public License v3.0

Makefile 0.35% Go 99.65%

go-design-pattern's Introduction

go 设计模式

Build Status GitHub license GitHub issues GitHub stars go1.11

设计模式的六大原则

1、开闭原则

对扩展开放,对修改关闭,简而言之:使用接口和抽象类

2、里氏代换原则

任何基类可以出现的地方,子类一定可以出现

3、依赖倒转原则

针对接口编程,依赖于抽象而不依赖于具体

4、接口隔离原则

使用多个隔离的接口,比使用单个接口要好,降低耦合,参考io包

5、迪米特法则,又称最少知道原则

一个实体应当尽量少地与其他实体之间发生相互作用,使得系统功能模块相对独立

6、合成复用原则

尽量使用合成/聚合的方式,而不是使用继承

总结:多使用接口,接口组合,针对接口编程

创建型模式

  • single 单例模式
  • abstractFactory 抽象工厂
  • builder 建造者模式
  • factoryMethod 工厂方法
  • prototype 原型模式
  • simpleFactory 简单工厂模式

结构型模式

  • adapter 适配器模式
  • bridge 桥接模式
  • composite 组合模式
  • decorator 装饰器模式
  • facade 外观模式
  • flyweight 享元模式
  • proxy 代理模式
  • options 选项模式

行为型模式

  • chain 责任链模式
  • command 命令模式
  • interperter 解释器模式
  • iterator 迭代器模式
  • mediator 中介者模式
  • memento 备忘录模式
  • observer 观察者模式
  • state 状态模式
  • strategy 策略模式
  • template 模板模式
  • visitor 访问者模式
参考资料

tmrts

BPing

qibin0506

HCLAC

go-design-pattern's People

Contributors

xiaomeng79 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.