mirror of
https://github.com/tmrts/go-patterns.git
synced 2024-11-25 06:26:06 +03:00
Include a summary for each pattern
This commit is contained in:
parent
25c473d8e0
commit
dc9da4ae32
92
README.md
92
README.md
@ -11,93 +11,89 @@
|
|||||||
[License]: http://creativecommons.org/licenses/by/4.0/
|
[License]: http://creativecommons.org/licenses/by/4.0/
|
||||||
A curated collection of idiomatic design & application patterns for Go language.
|
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__:
|
__Creational Patterns__:
|
||||||
|
|
||||||
| Pattern | Description |
|
| Pattern | Description |
|
||||||
|:-------:| ----------- |
|
|:-------:| ----------- |
|
||||||
| [Abstract Factory](abstract_factory.go) | use a generic function with specific factories |
|
| [Abstract Factory](abstract_factory.go) | Provides an interface for creating families of releated objects |
|
||||||
| [Singleton](singleton/singleton.go) | Restricts instantiation of a class to one object |
|
| [Builder](builder/builder.go) | Builds a complex object using simple objects |
|
||||||
| [Builder](builder/builder.go) | instead of using multiple constructors, builder object receives parameters and returns constructed objects |
|
| [Factory Method](factory_method.go) | Defers instantiation of an object to a specialized function for creating instances |
|
||||||
| [Factory Method](factory_method.go) | delegate a specialized function/method to create instances |
|
|
||||||
| [Lazy Evaluation](lazy_evaluation.go) | lazily-evaluated property pattern in Go |
|
|
||||||
| [Object Pool](object_pool/pool.go) | Instantiates and maintains a group of objects instances of the same type |
|
| [Object Pool](object_pool/pool.go) | Instantiates and maintains a group of objects instances of the same type |
|
||||||
|
| [Singleton](singleton/singleton.go) | Restricts instantiation of a class to one object |
|
||||||
|
|
||||||
__Structural Patterns__:
|
__Structural Patterns__:
|
||||||
|
|
||||||
| Pattern | Description |
|
| Pattern | Description |
|
||||||
|:-------:| ----------- |
|
|:-------:| ----------- |
|
||||||
| [Adapter](adapter.go) | adapt one interface to another using a white-list |
|
| [Adapter](adapter.go) | Adapts otherwise incompatible interfaces to work together by adapting one to the other |
|
||||||
| [Bridge](bridge.go) | a client-provider middleman to soften interface changes |
|
| [Bridge](bridge.go) | Decouples an interface from its implementation so that the two can vary independently |
|
||||||
| [Composite](composite.go) | encapsulate and provide access to a number of different objects |
|
| [Composite](composite.go) | Encapsulates and provides access to a number of different objects |
|
||||||
| [Decorator](decorator.go) | Adds behavior to an object, statically or dynamically |
|
| [Decorator](decorator.go) | Adds behavior to an object, statically or dynamically |
|
||||||
| [Facade](facade.go) | use one class as an API to a number of others |
|
| [Facade](facade.go) | Uses one class as an API to a number of others |
|
||||||
| [Flyweight](flyweight.go) | transparently reuse existing instances of objects with similar/identical state |
|
| [Flyweight](flyweight.go) | Reuses existing instances of objects with similar/identical state to minimize resource usage |
|
||||||
| [Model View Controller](mvc.go) | model<->view<->controller (non-strict relationships) |
|
| [Model View Controller](mvc.go) | Divides an app into three interconnected parts to separate internal representation from presentation to user |
|
||||||
| [Proxy](proxy.go) | an object funnels operations to something else |
|
| [Proxy](proxy.go) | Provides a surrogate for an object to control it's actions |
|
||||||
|
|
||||||
__Behavioral Patterns__:
|
__Behavioral Patterns__:
|
||||||
|
|
||||||
| Pattern | Description |
|
| Pattern | Description |
|
||||||
|:-------:| ----------- |
|
|:-------:| ----------- |
|
||||||
| [Chain](chain.go) | apply a chain of successive handlers to try and process the data |
|
| [Chain of Responsibility](chain_of_responsibility.go) | Avoids coupling a sender to receiver by giving more than object a chance to handle the request |
|
||||||
| [Catalog](catalog.go) | general methods will call different specialized methods based on construction parameter |
|
| [Command](command.go) | Bundles a command and arguments to call later |
|
||||||
| [Chaining Method](chaining_method.go) | continue callback next object method |
|
| [Mediator](mediator.go) | Connects objects and acts as a proxy |
|
||||||
| [Command](command.go) | bundle a command and arguments to call later |
|
| [Memento](memento.go) | Generate an opaque token that can be used to go back to a previous state |
|
||||||
| [Mediator](mediator.go) | an object that knows how to connect other objects and act as a proxy |
|
| [Observer](observer.go) | Provide a callback for notification of events/changes to data |
|
||||||
| [Memento](memento.go) | generate an opaque token that can be used to go back to a previous state |
|
| [Registry](registry.go) | Keep track of all subclasses of a given class |
|
||||||
| [Observer](observer.go) | provide a callback for notification of events/changes to data |
|
| [State](state.go) | Encapsulates varying behavior for the same object based on its internal state |
|
||||||
| [Registry](registry.go) | keep track of all subclasses of a given class |
|
| [Strategy](strategy/strategy.go) | Enables an algorithm's behavior to be selected at runtime |
|
||||||
| [Specification](specification.go) | business rules can be recombined by chaining the business rules together using boolean logic |
|
| [Template](template.go) | Defines a skeleton class which defers some methods to subclasses |
|
||||||
| [State](state.go) | logic is organized into a discrete number of potential states and the next state that can be transitioned to |
|
| [Visitor](visitor.go) | Separates an algorithm from an object on which it operates |
|
||||||
| [Strategy](strategy/strategy.go) | Encapsulates an algorithm inside a struct |
|
|
||||||
| [Template](template.go) | an object imposes a structure but takes pluggable components |
|
|
||||||
| [Visitor](visitor.go) | invoke a callback for all items of a collection |
|
|
||||||
|
|
||||||
__Synchronization Patterns__:
|
__Synchronization Patterns__:
|
||||||
|
|
||||||
| Pattern | Description |
|
| Pattern | Description |
|
||||||
|:-------:| ----------- |
|
|:-------:| ----------- |
|
||||||
| [Lock/Mutex](mutex/mutex.go) | Enforces mutual exclusion limit on accessing a resource |
|
| [Condition Variable](condition_variable.go) | Provides a mechanism for threads to temporarily give up access in order to wait for some condition |
|
||||||
| [Read-Write Lock](read_write_lock.go) | |
|
| [Lock/Mutex](mutex/mutex.go) | Enforces mutual exclusion limit on a resource to gain exclusive access |
|
||||||
| [Condition Variable](condition_variable.go) | |
|
|
||||||
| [Monitor](monitor.go) | Combination of mutex and condition variable patterns |
|
| [Monitor](monitor.go) | Combination of mutex and condition variable patterns |
|
||||||
|
| [Read-Write Lock](read_write_lock.go) | Allows parallel read access, but only exclusive access on write operations to a resource |
|
||||||
| [Semaphore](semaphore/semaphore.go) | Allows controlling access to a common resource |
|
| [Semaphore](semaphore/semaphore.go) | Allows controlling access to a common resource |
|
||||||
|
|
||||||
__Concurrency Patterns__:
|
__Concurrency Patterns__:
|
||||||
|
|
||||||
| Pattern | Description |
|
| Pattern | Description |
|
||||||
|:-------:| ----------- |
|
|:-------:| ----------- |
|
||||||
| [Scheduler](scheduler.go) | |
|
| [N-Barrier](barrier.go) | Prevents a process from proceeding until all N processes reach to the barrier |
|
||||||
| [Barrier](barrier.go) | |
|
|
||||||
| [Producer Consumer](producer_consumer.go) | |
|
|
||||||
| [Futures](future.go) | |
|
|
||||||
| [Broadcast](broadcast.go) | |
|
|
||||||
| [Multiplex](multiplex.go) | |
|
|
||||||
| [Generators](generator.go) | |
|
|
||||||
| [Coroutines](coroutine/coroutine.go) | |
|
|
||||||
| [Parallelism](parallelism/md5.go) | Completes large number of indenpendent tasks |
|
|
||||||
| [Bounded Parallelism](bounded_parallelism/md5.go) | Completes large number of indenpendent tasks with resource limits |
|
| [Bounded Parallelism](bounded_parallelism/md5.go) | Completes large number of indenpendent tasks with resource limits |
|
||||||
|
| [Broadcast](broadcast.go) | Transfers a message to all recipients simultaneously |
|
||||||
|
| [Coroutines](coroutine/coroutine.go) | Subroutines that allow suspending and resuming execution at certain locations |
|
||||||
|
| [Generators](generator.go) | Yields a sequence of values one at a time |
|
||||||
|
| [Reactor](reactor.go) | Demultiplexes service requests delivered concurrently to a service handler and dispatches them syncronously to the associated request handlers |
|
||||||
|
| [Parallelism](parallelism/md5.go) | Completes large number of indenpendent tasks |
|
||||||
|
| [Producer Consumer](producer_consumer.go) | Separates tasks from task executions |
|
||||||
|
| [Scheduler](scheduler.go) | Orchestrates steps to be performed as part of a task |
|
||||||
|
|
||||||
__Messaging Patterns__:
|
__Messaging Patterns__:
|
||||||
|
|
||||||
|
| Pattern | Description |
|
||||||
|
|:-------:| ----------- |
|
||||||
| [Fan-In](fan/fan_in.go) | Funnels tasks to a work sink (e.g. server) |
|
| [Fan-In](fan/fan_in.go) | Funnels tasks to a work sink (e.g. server) |
|
||||||
| [Fan-Out](fan/fan_out.go) | Distributes tasks amongs workers |
|
| [Fan-Out](fan/fan_out.go) | Distributes tasks amongs workers |
|
||||||
|
| [Futures & Promises](futures_promises.go) | Acts as a place-holder of a result that is initally unknown for synchronization purposes |
|
||||||
| [Publish/Subscribe](publish_subscribe.go) | Passes information to a collection of recipients who subscribed to a topic |
|
| [Publish/Subscribe](publish_subscribe.go) | Passes information to a collection of recipients who subscribed to a topic |
|
||||||
| [Request & Reply](fan) | |
|
| [Push & Pull](push_pull.go) | Distributes messages to multiple workers, arranged in a pipeline |
|
||||||
| [Push & Pull](fan) | |
|
|
||||||
|
|
||||||
|
|
||||||
__Stability Patterns__:
|
__Stability Patterns__:
|
||||||
|
|
||||||
| Pattern | Description |
|
| Pattern | Description |
|
||||||
|:-------:| ----------- |
|
|:-------:| ----------- |
|
||||||
| [Bulkheads](bulkhead.go) | |
|
| [Bulkheads](bulkhead.go) | Enforces a principle of failure containment (i.e. prevents cascading failures) |
|
||||||
| [Circuit Breaker](circuitbreaker/circuit_breaker.go) | Stops the flow of the requests when requests are likely to fail |
|
| [Circuit-Breaker](circuitbreaker/circuit_breaker.go) | Stops the flow of the requests when requests are likely to fail |
|
||||||
| [Deadline](deadline.go) | |
|
| [Deadline](deadline.go) | 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](fail_fast.go) | |
|
| [Fail-Fast](fail_fast.go) | Checks the availability of required resources at the start of a request and fails if the requirements are not satisfied |
|
||||||
| [Handshaking](handshaking.go) | |
|
| [Handshaking](handshaking.go) | Asks a component if it can take any more load, if it can't the request is declined |
|
||||||
| [Steady State](steady_state.go) | |
|
| [Steady-State](steady_state.go) | For every service that accumulates a resource, some other service must recycle that resource |
|
||||||
|
|
||||||
__Profiling Patterns__:
|
__Profiling Patterns__:
|
||||||
|
|
||||||
@ -115,7 +111,7 @@ __Anti-Patterns__:
|
|||||||
|
|
||||||
| Pattern | Description |
|
| Pattern | Description |
|
||||||
|:-------:| ----------- |
|
|:-------:| ----------- |
|
||||||
| [Cascading Failures]() | |
|
| [Cascading Failures]() | A failure in a system of interconnected parts in which the failure of a part causes a domino effect |
|
||||||
|
|
||||||
__Other Patterns__:
|
__Other Patterns__:
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user