1
0
mirror of https://github.com/tmrts/go-patterns.git synced 2024-11-21 20:46:08 +03:00
go-patterns/README.md
2016-02-20 17:35:39 +02:00

5.9 KiB

Go Patterns Travis Widget Awesome Widget License Widget

A curated collection of idiomatic design & application patterns for Go language.

For use cases please see the test files (files suffixed with _test).

Creational Patterns:

Pattern Description
Abstract Factory use a generic function with specific factories
Singleton Restricts instantiation of a class to one object
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 Instantiates and maintains a group of objects instances of the same type

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
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 variable patterns
Semaphore Allows controlling access to a common resource

Concurrency Patterns:

Pattern Description
Scheduler
Barrier
Producer Consumer
Futures
Broadcast
Multiplex
Generators
Coroutines
Parallelism Completes large number of indenpendent tasks
Bounded Parallelism Completes large number of indenpendent tasks with resource limits

Messaging Patterns: | Fan-In | Funnels tasks to a work sink (e.g. server) | | Fan-Out | Distributes tasks amongs workers | | Publish/Subscribe | Passes information to a collection of recipients who subscribed to a topic | | Request & Reply | | | Push & Pull | |

Stability Patterns:

Pattern Description
Bulkheads
Circuit Breaker Stops the flow of the requests when requests are likely to fail
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
Cascading Failures

Other Patterns:

Pattern Description

License

Creative Commons License

This work is licensed under a Creative Commons Attribution 4.0 International License.