Design Patterns in Go (Golang)
Design Patterns in Go (Golang)
Summary:
The book "Design Patterns in Go (Golang)" is a practical guide for developers who want to master classic design patterns (GoF) and learn to apply them in the Go ecosystem. Unlike Java or C++, Go has its own philosophy of composition and interfaces, so many patterns require adaptation. This book bridges the gap between classic descriptions and real Go code.
What the book covers
- Creational Patterns: Singleton, Factory Method, Abstract Factory, Builder, Prototype — how to create objects without tight coupling to types.
- Structural Patterns: Adapter, Bridge, Composite, Decorator, Facade, Flyweight, Proxy — ways to organize classes and structures into large systems.
- Behavioral Patterns: Chain of Responsibility, Command, Iterator, Mediator, Memento, Observer, State, Strategy, Template Method, Visitor — managing algorithms and object interactions.
- Go Specifics: Using interfaces, goroutines, and channels to implement patterns (e.g., Fan-Out/Fan-In as an alternative to Observer).
- Anti-patterns: Common mistakes when porting patterns from OOP languages to Go.
Who this book is for
- Junior and Middle Go developers — who want to move from writing "just working code" to architecturally sound solutions.
- Developers with experience in other languages — Java, C#, Python, who are learning Go and looking for analogs of familiar patterns.
- Software architects — who design microservices or high-load systems in Go.
What you will learn
- How to implement 23 classic patterns in pure Go without third-party libraries.
- Why Go often uses composition instead of inheritance and how this affects pattern selection.
- How to test code built on patterns using table-driven tests and mocks.
- How to combine patterns (e.g., Factory + Strategy) to solve real-world problems.
- How to refactor "spaghetti code" using patterns without breaking existing logic.
- Examples from real projects: web servers, CLI utilities, event handlers.
The book is written in a "problem → solution → Go code → discussion of alternatives" format. Each pattern is accompanied by UML diagrams and links to working examples on GitHub. You will be able to immediately apply the knowledge gained in your own projects.
If you want to write Go code not just quickly, but also with high quality — this book will become your desktop reference.