mirror of
https://github.com/tmrts/go-patterns.git
synced 2026-02-04 06:46:18 +00:00
4c276c72e17b0eedef58c87f79f651bd2048053c
Go Patterns

A curated collection of idiomatic design & application patterns for Go language.
Creational Patterns:
| Pattern | Description |
|---|---|
| Abstract Factory | use a generic function with specific factories |
| Borg Singleton | a singleton with shared-state among instances |
| Builder | instead of using multiple constructors, builder object receives parameters and returns constructed objects |
| Factory Method | delegate a specialized function/method to create instances |
| Lazy Evaluation | lazily-evaluated property pattern in Go |
| Object Pool | preinstantiate and maintain a group of instances of the same type |
| Prototype | use a factory and clones of a prototype for new instances (if instantiation is expensive) |
Structural Patterns:
| Pattern | Description |
|---|---|
| Adapter | adapt one interface to another using a white-list |
| Bridge | a client-provider middleman to soften interface changes |
| Composite | encapsulate and provide access to a number of different objects |
| Decorator | Adds behavior to an object, statically or dynamically |
| Facade | use one class as an API to a number of others |
| Flyweight | transparently reuse existing instances of objects with similar/identical state |
| Model View Controller | model<->view<->controller (non-strict relationships) |
| Proxy | an object funnels operations to something else |
Behavioral Patterns:
| Pattern | Description |
|---|---|
| Chain | apply a chain of successive handlers to try and process the data |
| Catalog | general methods will call different specialized methods based on construction parameter |
| Chaining Method | continue callback next object method |
| Command | bundle a command and arguments to call later |
| Mediator | an object that knows how to connect other objects and act as a proxy |
| Memento | generate an opaque token that can be used to go back to a previous state |
| Observer | provide a callback for notification of events/changes to data |
| Publish/Subscribe | Passes information to a collection of recipients who subscribed to a topic |
| Registry | keep track of all subclasses of a given class |
| Specification | business rules can be recombined by chaining the business rules together using boolean logic |
| State | logic is organized into a discrete number of potential states and the next state that can be transitioned to |
| Strategy | Encapsulates an algorithm inside a struct |
| Template | an object imposes a structure but takes pluggable components |
| Visitor | invoke a callback for all items of a collection |
Synchronization Patterns:
| Pattern | Description |
|---|---|
| Lock/Mutex | Enforces mutual exclusion limit on accessing a resource |
| Read-Write Lock | |
| Condition Variable | |
| Monitor | Combination of mutex and condition patterns |
| Semaphore | Allows controlling access to a common resource |
Concurrency Patterns:
| Pattern | Description |
|---|---|
| Scheduler | |
| Barrier | |
| Producer Consumer | |
| Futures | |
| Broadcast | |
| Multiplex | |
| Fan-In | |
| Generators | |
| Coroutines |
Stability Patterns:
| Pattern | Description |
|---|---|
| Bulkheads | |
| Circuit Breaker | |
| Deadline | |
| Fail Fast | |
| Handshaking | |
| Steady State |
Profiling Patterns:
| Pattern | Description |
|---|---|
| Timing Functions | Wraps a function and logs the execution |
Idioms:
| Pattern | Description |
|---|---|
| Functional Options | Allows creating clean APIs with sane defaults and idiomatic overrides |
Anti-Patterns:
| Pattern | Description |
|---|
Other Patterns:
| Pattern | Description |
|---|
License
This work is licensed under a Creative Commons Attribution 4.0 International License.
Description
Languages
Go
100%

