Golang 设计模式

Golang设计模式思想

  • 前言

    • 一切设计模式都是灵活应用struct的组合模式,以及go隐形继承接口的特性
    • go中的interface就是一些方法装饰, 而struct并不依赖于接口
  • 设计模式类型

创建模式

结构模式

  • 装饰模式(Decorator Pattern)
    • 装饰模式使用对象组合的方式动态改变或增加对象行为, 在原对象的基础上增加功能
      
  • 代理模式(Proxy Pattern)
    • 代理模式用于延迟处理操作或者在进行实际操作前后对真实对象进行其它处理。
      
  • 适配器模式(Adapter Pattern)
    • 将一个类的接口转换成客户希望的另外一个接口。适配器模式使得原本由于接口不兼容而不能一起工作的那些类可以一起工作
      
  • 组合模式(Composite)
    • 组合模式有助于表达数据结构, 将对象组合成树形结构以表示"部分-整体"的层次结构, 常用于树状的结构
      
  • 享元模式(Flyweight Pattern)
    • 把多个实例对象共同需要的数据,独立出一个享元,从而减少对象数量和节省内存
      
  • 外观模式(Facade Pattern)
    • 外观模式在客户端和现有系统之间加入一个外观对象, 为子系统提供一个统一的接入接口, 类似与委托
      
  • 桥接模式(Bridge Pattern)
    • 桥接模式分离抽象部分和实现部分,使得两部分可以独立扩展
      

行为模式

同步模式(synchronization patterns)

附录(设计模式彩图)

设计模式彩图

Owner
JKlee
Senior Software Engineer
JKlee
Similar Resources

An e-book on building network applications using golang

Network programming with Go

Dec 7, 2021

Golang Clean Architecture based on Uncle Bob's Clean Architecture and Summer internship in 2021

clean-architecture-api Description This is an example of implemention of Clean Architecture in Golang projects. This project has 4 layer : Infrastruct

Feb 20, 2022

Golang practice

practice Golang practice Move all files except one cut evrything from current directory and paste into stdinout/ directory mv !(stdinout) stdinout/ an

Dec 31, 2021

Programming Paradigm With Golang

Programming Paradigm With Golang

Programming-Paradigm After running python3 1_22.py you'll get a prompt: which, after entering start and the end of the interval, should create next wi

Oct 16, 2021

A practical journey into the Golang Programming Language

OneTutorial - A practical journey into the Golang Programming Language This little project will help you touch many topics around Golang, in a small a

Oct 21, 2021

Clean Architecture in Go (Golang) projects-DDD

Clean Architecture in Go (Golang) projects-DDD

go-clean-arch Changelog v1: checkout to the v1 branch Proposed on 2017, archived to v1 branch on 2018 Desc: Initial proposal by me. The story can be r

Oct 11, 2021

This is from the udemy course: Go: The Complete Developer's Guide (Golang)

Go Udemy course - "Go: The Complete Developer's Guide (Golang)" How to run the file: go run hello-world.go go run filename.go GO CLI commands: go ru

Oct 22, 2021

Here is the collection of beginner friendly golang projects

Golang Mini Projects for Beginners Here is the collection of beginner friendly golang projects Mini Projects Book Store cli app to list, add, update,

Dec 29, 2022

🚀✨🚀 REST API with Golang

REST API Statistics This repository is a completed test task for the Backend trainee position. Task text Technologies: Golang 1.17.1 Web framework - g

Dec 10, 2021
Comments
  • 关于sliice的空间节约

    关于sliice的空间节约

    你好,我在观察者模式代码里面发现这样一行代码

    share.oblist = append(share.oblist[:i], share.oblist[i+1:]...)

    当然不止一处是这种写法

    这样删除元素,它引用的底层数组还是同一个,如果删除多个的话,len远小于cap,有些浪费空间,不如每次删除的时候重新创建一个slice存放剩下的元素,我看很多项目删除元素都是这样做的

7 days golang programs from scratch (web framework Gee, distributed cache GeeCache, object relational mapping ORM framework GeeORM, rpc framework GeeRPC etc) 7天用Go动手写/从零实现系列

7 days golang programs from scratch README 中文版本 7天用Go从零实现系列 7天能写什么呢?类似 gin 的 web 框架?类似 groupcache 的分布式缓存?或者一个简单的 Python 解释器?希望这个仓库能给你答案

Jan 5, 2023
Examples of Golang compared to Node.js for learning
Examples of Golang compared to Node.js for learning

This guide full of examples is intended for people learning Go that are coming from Node.js, although the vice versa can work too. This is not meant to be a complete guide and it is assumed that you've gone through the Tour of Go tutorial. This guide is meant to be barely good enough to help you at a high level understand how to do X in Y and doing further learning on your own is of course required.

Jan 9, 2023
Golang && Back-end Stack , Continually updated

Stack Here Golang OS Net Note Tool Delve Authentication Paper Paper ?? Link GO官方文档 GO Official Doc GO官方博客 GO Official Blog GO官方仓库

Nov 8, 2022
The Ultimate Workshop Track for #golang Developer
The Ultimate Workshop Track  for #golang Developer

layout title nav_order description permalink default An Ultimate GopherLabs Hands-on Labs 1 An Ultimate GopherLabs Hands-on Labs / Join GopherLabs Com

Dec 7, 2022
high performance coding with golang(Go 语言高性能编程,Go 语言陷阱,Gotchas,Traps)
high performance coding with golang(Go 语言高性能编程,Go 语言陷阱,Gotchas,Traps)

Go 语言高性能编程 订阅 最新动态可以关注:知乎 Go语言 或微博 极客兔兔 订阅方式:watch geektutu/blog ,每篇文章都能收到邮件通知,或通过 RSS 订阅。

Dec 28, 2022
Go-Notebook is inspired by Jupyter Project (link) in order to document Golang code.
Go-Notebook is inspired by Jupyter Project (link) in order to document Golang code.

Go-Notebook Go-Notebook is an app that was developed using go-echo-live-view framework, developed also by us. GitHub repository is here. For this proj

Jan 9, 2023
Crash Course about the programming language Go / Golang.
Crash Course about the programming language Go / Golang.

Crash Course about the programming language Go / Golang. In this course I have covered some important concepts and topics in programming.

Oct 10, 2022
Building a shoe store with golang to learn more about this language :)

shoestore-go Building a shoe store with golang to learn more about this language :) TODO Create a basic webpage with the pages: home : to show homepag

Jan 24, 2022
Golang Learning resources

golang Golang Learning resources Data type detection dataFields interface{} dtype := reflect.TypeOf(dataFields).Kind().String() var c Company fmt.Prin

Dec 14, 2022
A complete guide to undersatnd golang programming language, web requests, JSON and creating web APIs with mongodb

Golang series A complete guide to undersatnd golang programming language, web requests, JSON and creating web APIs with mongodb LearnCodeonline.in 01

Jan 1, 2023