awesome-patterns/README.md
2020-05-03 01:32:15 +08:00

7.4 KiB

Go Patterns
build-status awesome license

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

Creational Patterns

Pattern Description Status
Abstract Factory Provides an interface for creating families of releated objects âœ
Builder Builds a complex object using simple objects âœ
Factory Method Defers instantiation of an object to a specialized function for creating instances âœ
Object Pool Instantiates and maintains a group of objects instances of the same type âœ
Singleton Restricts instantiation of a type to one object âœ

Structural Patterns

Pattern Description Status
Bridge Decouples an interface from its implementation so that the two can vary independently âœ
Composite Encapsulates and provides access to a number of different objects âœ
Decorator Adds behavior to an object, statically or dynamically âœ
Facade Uses one type as an API to a number of others âœ
Flyweight Reuses existing instances of objects with similar/identical state to minimize resource usage âœ
Proxy Provides a surrogate for an object to control it's actions âœ

Behavioral Patterns

Pattern Description Status
Chain of Responsibility Avoids coupling a sender to receiver by giving more than object a chance to handle the request âœ
Command Bundles a command and arguments to call later âœ
Mediator Connects objects and acts 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 âœ
State Encapsulates varying behavior for the same object based on its internal state âœ
Strategy Enables an algorithm's behavior to be selected at runtime âœ
Template Defines a skeleton class which defers some methods to subclasses âœ
Visitor Separates an algorithm from an object on which it operates âœ

Synchronization Patterns

Pattern Description Status
Condition Variable Provides a mechanism for threads to temporarily give up access in order to wait for some condition âœ
Lock/Mutex Enforces mutual exclusion limit on a resource to gain exclusive access âœ
Monitor Combination of mutex and condition variable patterns âœ
Read-Write Lock Allows parallel read access, but only exclusive access on write operations to a resource âœ
Semaphore Allows controlling access to a common resource âœ

Concurrency Patterns

Pattern Description Status
N-Barrier Prevents a process from proceeding until all N processes reach to the barrier âœ
Bounded Parallelism Completes large number of independent tasks with resource limits âœ
Broadcast Transfers a message to all recipients simultaneously âœ
Coroutines Subroutines that allow suspending and resuming execution at certain locations âœ
Generators Yields a sequence of values one at a time âœ
Reactor Demultiplexes service requests delivered concurrently to a service handler and dispatches them syncronously to the associated request handlers âœ
Parallelism Completes large number of independent tasks âœ
Producer Consumer Separates tasks from task executions âœ

Messaging Patterns

Pattern Description Status
Fan-In Funnels tasks to a work sink (e.g. server) âœ
Fan-Out Distributes tasks among workers (e.g. producer) âœ
Futures & Promises Acts as a place-holder of a result that is initially unknown for synchronization purposes âœ
Publish/Subscribe Passes information to a collection of recipients who subscribed to a topic âœ
Push & Pull Distributes messages to multiple workers, arranged in a pipeline âœ

Stability Patterns

Pattern Description Status
Bulkheads Enforces a principle of failure containment (i.e. prevents cascading failures) âœ
Circuit-Breaker Stops the flow of the requests when requests are likely to fail âœ
Deadline Allows clients to stop waiting for a response once the probability of response becomes low (e.g. after waiting 10 seconds for a page refresh) âœ
Fail-Fast Checks the availability of required resources at the start of a request and fails if the requirements are not satisfied âœ
Handshaking Asks a component if it can take any more load, if it can't, the request is declined âœ
Steady-State For every service that accumulates a resource, some other service must recycle that resource âœ

Profiling Patterns

Pattern Description Status
Timing Functions Wraps a function and logs the execution âœ

Idioms

Pattern Description Status
Functional Options Allows creating clean APIs with sane defaults and idiomatic overrides âœ

Anti-Patterns

Pattern Description Status
Cascading Failures A failure in a system of interconnected parts in which the failure of a part causes a domino effect âœ