Giter VIP home page Giter VIP logo

designpatterns's Introduction

golang 23种设计模式

设计原则

目的:高内聚,低耦合

  • 单一职责原则
    • 一个类一个功能方法,但是会导致代码耦合度高,所以需要平衡
  • 开闭原则
    • 添加功能时不能更改原有代码,所以原有类设计的时候我们使用interface,继承时实现功能(比如直接添加原来类的方法,因为源代码有耦合度)
    • 可以使用interface当作参数动态替换成实现类进行多态
  • 里氏替换原则
    • 尽量使用接口
  • 依赖倒转原则
    • 业务逻辑层(main) 和 实现层(struct) 都依赖于 抽象层(interface)
  • 接口隔离原则
    • 接口的单一职责
  • 合成复用原则
    • 使用组合代替继承,一个类是另一个类的属性或形参
  • 迪米特原则
    • 模块相互调用使用接口,黑盒

设计模式

designpatterns's People

Contributors

f4-11 avatar

Watchers

 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.