Skip to content

A comprehensive, production-ready collection of Go design patterns with executable examples. From classic Gang of Four to modern Go-specific and concurrency patterns. Perfect for learning, reference, and writing idiomatic Go code.

Notifications You must be signed in to change notification settings

dll-as/go-patterns

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🐹 Go Design Patterns Collection

A comprehensive, practical, and production-ready collection of Go design patterns
Learn • Reference • Practice

🌟 Why This Repository?

This isn't just another list of Go patterns. It's a hands-on, production-aware collection where every pattern comes with:

Feature Description
Runable Code Every pattern has a main.go you can execute immediately
📖 Detailed README Each directory explains when/why/how to use the pattern
🎯 Go-Specific Patterns adapted to Go idioms, not Java/C++ translations
🔧 Practical Examples Real-world scenarios, not just theoretical Animal/Shape examples
📊 Multiple Categories From classic Gang of Four to modern Go concurrency patterns

📚 Table of Contents

🏗️ Creational Patterns — Object creation mechanisms
  • Singleton — Ensure a type has only one instance
  • Factory Method — Delegate object creation to subclasses
  • Abstract Factory — Create families of related objects
  • Builder — Construct complex objects step by step
  • Prototype — Clone objects instead of creating from scratch
🔌 Structural Patterns — Object composition and relationships
  • Adapter — Make incompatible interfaces compatible
  • Bridge — Separate abstraction from implementation
  • Composite — Treat individual and composite objects uniformly
  • Decorator — Add behavior without inheritance
  • Facade — Simplify complex subsystems
  • Flyweight — Share objects to support large quantities
  • Proxy — Control access to another object
🔄 Behavioral Patterns — Object communication and responsibility
  • Chain of Responsibility — Pass requests along a chain
  • Command — Encapsulate requests as objects
  • Interpreter — Define a grammar and interpret sentences
  • Iterator — Traverse collections without exposing internals
  • Mediator — Reduce coupling between objects
  • Memento — Capture and restore object state
  • Observer — Notify dependents of state changes
  • State — Alter behavior when state changes
  • Strategy — Select algorithms at runtime
  • Template Method — Define skeleton of an algorithm
  • Visitor — Separate algorithms from objects
⚡ Concurrency Patterns — Go's superpower! Goroutines & channels
🎯 Go-Specific Patterns — Idiomatic Go practices
🏛️ Architectural Patterns — System-level organization

🚀 Quick Start

# Clone the repository
git clone https://github.com/dll-as/go-patterns.git
cd go-patterns

# Pick a pattern and run it!
cd Creational/singleton
go run main.go

# Or run tests if available
cd Go-Specific/table-driven-tests
go test -v

📖 How to Read This Repository

  • 🎓 For Beginners

    Start with Creational patterns — they're the most intuitive. Then move to Structural and Behavioral. Each pattern's README explains the "what" and "why" before the "how".

  • 🚗 For Experienced Gophers

    Jump straight to Concurrency and Go-Specific patterns. These show you how Go differs from other launguages and how to write idiomatic Go code.

  • 🏗️ For Architects

    The Architectural patterns section demonstrates how to structure entire applications. See how clean architecture and hexagonal architecture are implemented in Go.

  • ✨ What Makes a Good Pattern Example?

    Each pattern directory contains:

    pattern-name/
    ├── main.go           # Runnable, self-contained example
    ├── README.md         # Detailed explanation with:
    │                     # • Intent & Problem
    │                     # • Solution & Structure
    │                     # • When to use/avoid
    │                     # • Real-world examples
    │                     # • Comparison with other patterns
    └── main_test.go      # Optional: Tests showing usage
    

About

A comprehensive, production-ready collection of Go design patterns with executable examples. From classic Gang of Four to modern Go-specific and concurrency patterns. Perfect for learning, reference, and writing idiomatic Go code.

Topics

Resources

Stars

Watchers

Forks

Languages