explaingit

senghoo/golang-design-pattern

9,022GoAudience · developerComplexity · 1/5Setup · easy

TLDR

A learning reference with working Go code examples for all 23 classic software design patterns, creational, structural, and behavioral, organized one pattern per folder.

Mindmap

mindmap
  root((golang-design-pattern))
    Creational
      Factory patterns
      Builder
      Singleton
    Structural
      Adapter
      Decorator
      Proxy
    Behavioral
      Observer
      Strategy
      Command
    Learning
      Code examples
      Pattern reference
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Study how classic design patterns like Observer, Strategy, or Singleton look when implemented in Go.

USE CASE 2

Use as a quick reference when adding a Decorator or Proxy pattern to your own Go project.

USE CASE 3

Learn software design patterns for the first time using real working code alongside a textbook.

USE CASE 4

Compare multiple patterns side by side to decide which one fits your current architecture problem.

Tech stack

Go

Getting it running

Difficulty · easy Time to first run · 5min

In plain English

This repository is a collection of example code in Go that demonstrates classic software design patterns. Design patterns are reusable solutions to common problems that come up repeatedly when building software. Rather than inventing a new approach every time, developers use these named patterns as a shared vocabulary and starting point. The repository is described as reading notes from the book "Research on Design Patterns" and covers 23 patterns organized into three categories. The first category, creational patterns, covers ways to create objects: Simple Factory, Factory Method, Abstract Factory, Builder, Prototype, and Singleton. The second category, structural patterns, covers how to organize or combine components: Facade, Adapter, Proxy, Composite, Flyweight, Decorator, and Bridge. The third category, behavioral patterns, covers how components communicate and coordinate: Mediator, Observer, Command, Iterator, Template Method, Strategy, State, Memento, Interpreter, Chain of Responsibility, and Visitor. Each pattern has its own folder in the repository containing Go code that shows how to implement it. The README is written in Chinese and serves mainly as an index linking to each of the 23 pattern folders on GitHub. This is primarily a learning resource. If you are studying Go and want to understand how established design patterns look when written in Go specifically, or if you are learning design patterns for the first time and want working code examples alongside your reading, this repository provides a concise reference.

Copy-paste prompts

Prompt 1
I am implementing the Observer pattern in my Go project. Show me how the example in golang-design-pattern works and help me adapt it to notify subscribers when a database record changes.
Prompt 2
Explain the difference between the Factory Method and Abstract Factory patterns using the Go code examples from golang-design-pattern, in plain English.
Prompt 3
I want to refactor a large switch statement in my Go code using the Strategy pattern. Walk me through the strategy pattern example and how to apply it to my situation.
Prompt 4
Help me understand when to use the Decorator pattern versus the Proxy pattern in Go, using the golang-design-pattern examples as a reference.
Open on GitHub → Explain another repo

← senghoo on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.