mirror of
https://github.com/tmrts/go-patterns.git
synced 2024-11-22 13:06:09 +03:00
1400 lines
38 KiB
HTML
1400 lines
38 KiB
HTML
|
|
<!DOCTYPE HTML>
|
|
<html lang="" >
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
|
|
<title>Go Patterns · GitBook</title>
|
|
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
|
<meta name="description" content="">
|
|
<meta name="generator" content="GitBook 3.2.2">
|
|
|
|
|
|
|
|
|
|
<link rel="stylesheet" href="gitbook/style.css">
|
|
|
|
|
|
|
|
|
|
<link rel="stylesheet" href="gitbook/gitbook-plugin-highlight/website.css">
|
|
|
|
|
|
|
|
<link rel="stylesheet" href="gitbook/gitbook-plugin-fontsettings/website.css">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<meta name="HandheldFriendly" content="true"/>
|
|
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
|
|
<meta name="apple-mobile-web-app-capable" content="yes">
|
|
<meta name="apple-mobile-web-app-status-bar-style" content="black">
|
|
<link rel="apple-touch-icon-precomposed" sizes="152x152" href="gitbook/images/apple-touch-icon-precomposed-152.png">
|
|
<link rel="shortcut icon" href="gitbook/images/favicon.ico" type="image/x-icon">
|
|
|
|
|
|
<link rel="next" href="./" />
|
|
|
|
|
|
|
|
</head>
|
|
<body>
|
|
|
|
<div class="book">
|
|
<div class="book-summary">
|
|
|
|
|
|
|
|
<nav role="navigation">
|
|
|
|
|
|
|
|
<ul class="summary">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<li class="chapter active" data-level="1.1" data-path="./">
|
|
|
|
<a href="./">
|
|
|
|
|
|
Go Patterns
|
|
|
|
</a>
|
|
|
|
|
|
|
|
<ul class="articles">
|
|
|
|
|
|
<li class="chapter " data-level="1.1.1" data-path="./">
|
|
|
|
<a href="./#creational-patterns">
|
|
|
|
|
|
Creational Patterns
|
|
|
|
</a>
|
|
|
|
|
|
|
|
<ul class="articles">
|
|
|
|
|
|
<li class="chapter " data-level="1.1.1.1" data-path="creational/abstract_factory.md">
|
|
|
|
<span>
|
|
|
|
|
|
Abstract Factory
|
|
|
|
</a>
|
|
|
|
|
|
|
|
</li>
|
|
|
|
<li class="chapter " data-level="1.1.1.2" data-path="creational/builder.html">
|
|
|
|
<a href="creational/builder.html">
|
|
|
|
|
|
Builder
|
|
|
|
</a>
|
|
|
|
|
|
|
|
</li>
|
|
|
|
<li class="chapter " data-level="1.1.1.3" data-path="creational/factory.html">
|
|
|
|
<a href="creational/factory.html">
|
|
|
|
|
|
Factory Method
|
|
|
|
</a>
|
|
|
|
|
|
|
|
</li>
|
|
|
|
<li class="chapter " data-level="1.1.1.4" data-path="creational/object-pool.html">
|
|
|
|
<a href="creational/object-pool.html">
|
|
|
|
|
|
Object Pool
|
|
|
|
</a>
|
|
|
|
|
|
|
|
</li>
|
|
|
|
<li class="chapter " data-level="1.1.1.5" data-path="creational/singleton.html">
|
|
|
|
<a href="creational/singleton.html">
|
|
|
|
|
|
Singleton
|
|
|
|
</a>
|
|
|
|
|
|
|
|
</li>
|
|
|
|
|
|
</ul>
|
|
|
|
</li>
|
|
|
|
<li class="chapter " data-level="1.1.2" data-path="./">
|
|
|
|
<a href="./#structural-patterns">
|
|
|
|
|
|
Structural Patterns
|
|
|
|
</a>
|
|
|
|
|
|
|
|
<ul class="articles">
|
|
|
|
|
|
<li class="chapter " data-level="1.1.2.1" data-path="structural/bridge.md">
|
|
|
|
<span>
|
|
|
|
|
|
Bridge
|
|
|
|
</a>
|
|
|
|
|
|
|
|
</li>
|
|
|
|
<li class="chapter " data-level="1.1.2.2" data-path="structural/composite.md">
|
|
|
|
<span>
|
|
|
|
|
|
Composite
|
|
|
|
</a>
|
|
|
|
|
|
|
|
</li>
|
|
|
|
<li class="chapter " data-level="1.1.2.3" data-path="structural/decorator.html">
|
|
|
|
<a href="structural/decorator.html">
|
|
|
|
|
|
Decorator
|
|
|
|
</a>
|
|
|
|
|
|
|
|
</li>
|
|
|
|
<li class="chapter " data-level="1.1.2.4" data-path="structural/facade.md">
|
|
|
|
<span>
|
|
|
|
|
|
Facade
|
|
|
|
</a>
|
|
|
|
|
|
|
|
</li>
|
|
|
|
<li class="chapter " data-level="1.1.2.5" data-path="structural/flyweight.md">
|
|
|
|
<span>
|
|
|
|
|
|
Flyweight
|
|
|
|
</a>
|
|
|
|
|
|
|
|
</li>
|
|
|
|
<li class="chapter " data-level="1.1.2.6" data-path="structural/proxy.md">
|
|
|
|
<span>
|
|
|
|
|
|
Proxy
|
|
|
|
</a>
|
|
|
|
|
|
|
|
</li>
|
|
|
|
|
|
</ul>
|
|
|
|
</li>
|
|
|
|
<li class="chapter " data-level="1.1.3" data-path="./">
|
|
|
|
<a href="./#behavioral-patterns">
|
|
|
|
|
|
Behavioral Patterns
|
|
|
|
</a>
|
|
|
|
|
|
|
|
<ul class="articles">
|
|
|
|
|
|
<li class="chapter " data-level="1.1.3.1" data-path="behavioral/chain_of_responsibility.md">
|
|
|
|
<span>
|
|
|
|
|
|
Chain of Responsibility
|
|
|
|
</a>
|
|
|
|
|
|
|
|
</li>
|
|
|
|
<li class="chapter " data-level="1.1.3.2" data-path="behavioral/command.md">
|
|
|
|
<span>
|
|
|
|
|
|
Command
|
|
|
|
</a>
|
|
|
|
|
|
|
|
</li>
|
|
|
|
<li class="chapter " data-level="1.1.3.3" data-path="behavioral/mediator.md">
|
|
|
|
<span>
|
|
|
|
|
|
Mediator
|
|
|
|
</a>
|
|
|
|
|
|
|
|
</li>
|
|
|
|
<li class="chapter " data-level="1.1.3.4" data-path="behavioral/memento.md">
|
|
|
|
<span>
|
|
|
|
|
|
Memento
|
|
|
|
</a>
|
|
|
|
|
|
|
|
</li>
|
|
|
|
<li class="chapter " data-level="1.1.3.5" data-path="behavioral/observer.html">
|
|
|
|
<a href="behavioral/observer.html">
|
|
|
|
|
|
Observer
|
|
|
|
</a>
|
|
|
|
|
|
|
|
</li>
|
|
|
|
<li class="chapter " data-level="1.1.3.6" data-path="behavioral/registry.md">
|
|
|
|
<span>
|
|
|
|
|
|
Registry
|
|
|
|
</a>
|
|
|
|
|
|
|
|
</li>
|
|
|
|
<li class="chapter " data-level="1.1.3.7" data-path="behavioral/state.md">
|
|
|
|
<span>
|
|
|
|
|
|
State
|
|
|
|
</a>
|
|
|
|
|
|
|
|
</li>
|
|
|
|
<li class="chapter " data-level="1.1.3.8" data-path="behavioral/strategy.html">
|
|
|
|
<a href="behavioral/strategy.html">
|
|
|
|
|
|
Strategy
|
|
|
|
</a>
|
|
|
|
|
|
|
|
</li>
|
|
|
|
<li class="chapter " data-level="1.1.3.9" data-path="behavioral/template.md">
|
|
|
|
<span>
|
|
|
|
|
|
Template
|
|
|
|
</a>
|
|
|
|
|
|
|
|
</li>
|
|
|
|
<li class="chapter " data-level="1.1.3.10" data-path="behavioral/visitor.md">
|
|
|
|
<span>
|
|
|
|
|
|
Visitor
|
|
|
|
</a>
|
|
|
|
|
|
|
|
</li>
|
|
|
|
|
|
</ul>
|
|
|
|
</li>
|
|
|
|
<li class="chapter " data-level="1.1.4" data-path="./">
|
|
|
|
<a href="./#synchronization-patterns">
|
|
|
|
|
|
Synchronization Patterns
|
|
|
|
</a>
|
|
|
|
|
|
|
|
<ul class="articles">
|
|
|
|
|
|
<li class="chapter " data-level="1.1.4.1" data-path="synchronization/condition_variable.md">
|
|
|
|
<span>
|
|
|
|
|
|
Condition Variable
|
|
|
|
</a>
|
|
|
|
|
|
|
|
</li>
|
|
|
|
<li class="chapter " data-level="1.1.4.2" data-path="synchronization/mutex.md">
|
|
|
|
<span>
|
|
|
|
|
|
Lock/Mutex
|
|
|
|
</a>
|
|
|
|
|
|
|
|
</li>
|
|
|
|
<li class="chapter " data-level="1.1.4.3" data-path="synchronization/monitor.md">
|
|
|
|
<span>
|
|
|
|
|
|
Monitor
|
|
|
|
</a>
|
|
|
|
|
|
|
|
</li>
|
|
|
|
<li class="chapter " data-level="1.1.4.4" data-path="synchronization/read_write_lock.md">
|
|
|
|
<span>
|
|
|
|
|
|
Read-Write Lock
|
|
|
|
</a>
|
|
|
|
|
|
|
|
</li>
|
|
|
|
<li class="chapter " data-level="1.1.4.5" data-path="synchronization/semaphore.html">
|
|
|
|
<a href="synchronization/semaphore.html">
|
|
|
|
|
|
Semaphore
|
|
|
|
</a>
|
|
|
|
|
|
|
|
</li>
|
|
|
|
|
|
</ul>
|
|
|
|
</li>
|
|
|
|
<li class="chapter " data-level="1.1.5" data-path="./">
|
|
|
|
<a href="./#concurrency-patterns">
|
|
|
|
|
|
Concurrency Patterns
|
|
|
|
</a>
|
|
|
|
|
|
|
|
<ul class="articles">
|
|
|
|
|
|
<li class="chapter " data-level="1.1.5.1" data-path="concurrency/barrier.md">
|
|
|
|
<span>
|
|
|
|
|
|
N-Barrier
|
|
|
|
</a>
|
|
|
|
|
|
|
|
</li>
|
|
|
|
<li class="chapter " data-level="1.1.5.2" data-path="concurrency/bounded_parallelism.html">
|
|
|
|
<a href="concurrency/bounded_parallelism.html">
|
|
|
|
|
|
Bounded Parallelism
|
|
|
|
</a>
|
|
|
|
|
|
|
|
</li>
|
|
|
|
<li class="chapter " data-level="1.1.5.3" data-path="concurrency/broadcast.md">
|
|
|
|
<span>
|
|
|
|
|
|
Broadcast
|
|
|
|
</a>
|
|
|
|
|
|
|
|
</li>
|
|
|
|
<li class="chapter " data-level="1.1.5.4" data-path="concurrency/coroutine.md">
|
|
|
|
<span>
|
|
|
|
|
|
Coroutines
|
|
|
|
</a>
|
|
|
|
|
|
|
|
</li>
|
|
|
|
<li class="chapter " data-level="1.1.5.5" data-path="concurrency/generator.html">
|
|
|
|
<a href="concurrency/generator.html">
|
|
|
|
|
|
Generators
|
|
|
|
</a>
|
|
|
|
|
|
|
|
</li>
|
|
|
|
<li class="chapter " data-level="1.1.5.6" data-path="concurrency/reactor.md">
|
|
|
|
<span>
|
|
|
|
|
|
Reactor
|
|
|
|
</a>
|
|
|
|
|
|
|
|
</li>
|
|
|
|
<li class="chapter " data-level="1.1.5.7" data-path="concurrency/parallelism.html">
|
|
|
|
<a href="concurrency/parallelism.html">
|
|
|
|
|
|
Parallelism
|
|
|
|
</a>
|
|
|
|
|
|
|
|
</li>
|
|
|
|
<li class="chapter " data-level="1.1.5.8" data-path="concurrency/producer_consumer.md">
|
|
|
|
<span>
|
|
|
|
|
|
Producer Consumer
|
|
|
|
</a>
|
|
|
|
|
|
|
|
</li>
|
|
|
|
|
|
</ul>
|
|
|
|
</li>
|
|
|
|
<li class="chapter " data-level="1.1.6" data-path="./">
|
|
|
|
<a href="./#messaging-patterns">
|
|
|
|
|
|
Messaging Patterns
|
|
|
|
</a>
|
|
|
|
|
|
|
|
<ul class="articles">
|
|
|
|
|
|
<li class="chapter " data-level="1.1.6.1" data-path="messaging/fan_in.html">
|
|
|
|
<a href="messaging/fan_in.html">
|
|
|
|
|
|
Fan-In
|
|
|
|
</a>
|
|
|
|
|
|
|
|
</li>
|
|
|
|
<li class="chapter " data-level="1.1.6.2" data-path="messaging/fan_out.html">
|
|
|
|
<a href="messaging/fan_out.html">
|
|
|
|
|
|
Fan-Out
|
|
|
|
</a>
|
|
|
|
|
|
|
|
</li>
|
|
|
|
<li class="chapter " data-level="1.1.6.3" data-path="messaging/futures_promises.md">
|
|
|
|
<span>
|
|
|
|
|
|
Futures & Promises
|
|
|
|
</a>
|
|
|
|
|
|
|
|
</li>
|
|
|
|
<li class="chapter " data-level="1.1.6.4" data-path="messaging/publish_subscribe.html">
|
|
|
|
<a href="messaging/publish_subscribe.html">
|
|
|
|
|
|
Publish/Subscribe
|
|
|
|
</a>
|
|
|
|
|
|
|
|
</li>
|
|
|
|
<li class="chapter " data-level="1.1.6.5" data-path="messaging/push_pull.md">
|
|
|
|
<span>
|
|
|
|
|
|
Push & Pull
|
|
|
|
</a>
|
|
|
|
|
|
|
|
</li>
|
|
|
|
|
|
</ul>
|
|
|
|
</li>
|
|
|
|
<li class="chapter " data-level="1.1.7" data-path="./">
|
|
|
|
<a href="./#stability-patterns">
|
|
|
|
|
|
Stability Patterns
|
|
|
|
</a>
|
|
|
|
|
|
|
|
<ul class="articles">
|
|
|
|
|
|
<li class="chapter " data-level="1.1.7.1" data-path="stability/bulkhead.md">
|
|
|
|
<span>
|
|
|
|
|
|
Bulkheads
|
|
|
|
</a>
|
|
|
|
|
|
|
|
</li>
|
|
|
|
<li class="chapter " data-level="1.1.7.2" data-path="stability/circuit-breaker.html">
|
|
|
|
<a href="stability/circuit-breaker.html">
|
|
|
|
|
|
Circuit-Breaker
|
|
|
|
</a>
|
|
|
|
|
|
|
|
</li>
|
|
|
|
<li class="chapter " data-level="1.1.7.3" data-path="stability/deadline.md">
|
|
|
|
<span>
|
|
|
|
|
|
Deadline
|
|
|
|
</a>
|
|
|
|
|
|
|
|
</li>
|
|
|
|
<li class="chapter " data-level="1.1.7.4" data-path="stability/fail_fast.md">
|
|
|
|
<span>
|
|
|
|
|
|
Fail-Fast
|
|
|
|
</a>
|
|
|
|
|
|
|
|
</li>
|
|
|
|
<li class="chapter " data-level="1.1.7.5" data-path="stability/handshaking.md">
|
|
|
|
<span>
|
|
|
|
|
|
Handshaking
|
|
|
|
</a>
|
|
|
|
|
|
|
|
</li>
|
|
|
|
<li class="chapter " data-level="1.1.7.6" data-path="stability/steady_state.md">
|
|
|
|
<span>
|
|
|
|
|
|
Steady-State
|
|
|
|
</a>
|
|
|
|
|
|
|
|
</li>
|
|
|
|
|
|
</ul>
|
|
|
|
</li>
|
|
|
|
<li class="chapter " data-level="1.1.8" data-path="./">
|
|
|
|
<a href="./#profiling-patterns">
|
|
|
|
|
|
Profiling Patterns
|
|
|
|
</a>
|
|
|
|
|
|
|
|
<ul class="articles">
|
|
|
|
|
|
<li class="chapter " data-level="1.1.8.1" data-path="profiling/timing.html">
|
|
|
|
<a href="profiling/timing.html">
|
|
|
|
|
|
Timing Functions
|
|
|
|
</a>
|
|
|
|
|
|
|
|
</li>
|
|
|
|
|
|
</ul>
|
|
|
|
</li>
|
|
|
|
<li class="chapter " data-level="1.1.9" data-path="./">
|
|
|
|
<a href="./#idioms">
|
|
|
|
|
|
Idioms
|
|
|
|
</a>
|
|
|
|
|
|
|
|
<ul class="articles">
|
|
|
|
|
|
<li class="chapter " data-level="1.1.9.1" data-path="idiom/functional-options.html">
|
|
|
|
<a href="idiom/functional-options.html">
|
|
|
|
|
|
Functional Options
|
|
|
|
</a>
|
|
|
|
|
|
|
|
</li>
|
|
|
|
|
|
</ul>
|
|
|
|
</li>
|
|
|
|
<li class="chapter " data-level="1.1.10" data-path="./">
|
|
|
|
<a href="./#anti-patterns">
|
|
|
|
|
|
Anti-Patterns
|
|
|
|
</a>
|
|
|
|
|
|
|
|
<ul class="articles">
|
|
|
|
|
|
<li class="chapter " data-level="1.1.10.1" data-path="anti-patterns/cascading_failures.md">
|
|
|
|
<span>
|
|
|
|
|
|
Cascading Failures
|
|
|
|
</a>
|
|
|
|
|
|
|
|
</li>
|
|
|
|
|
|
</ul>
|
|
|
|
</li>
|
|
|
|
|
|
</ul>
|
|
|
|
</li>
|
|
|
|
<li class="chapter " data-level="1.2" data-path="CONTRIBUTING.html">
|
|
|
|
<a href="CONTRIBUTING.html">
|
|
|
|
|
|
Contributing
|
|
|
|
</a>
|
|
|
|
|
|
|
|
</li>
|
|
|
|
|
|
|
|
|
|
<li class="divider"></li>
|
|
|
|
<li>
|
|
<a href="https://www.gitbook.com" target="blank" class="gitbook-link">
|
|
Published with GitBook
|
|
</a>
|
|
</li>
|
|
</ul>
|
|
|
|
|
|
</nav>
|
|
|
|
|
|
</div>
|
|
|
|
<div class="book-body">
|
|
|
|
<div class="body-inner">
|
|
|
|
|
|
|
|
<div class="book-header" role="navigation">
|
|
|
|
|
|
<!-- Title -->
|
|
<h1>
|
|
<i class="fa fa-circle-o-notch fa-spin"></i>
|
|
<a href="." >Go Patterns</a>
|
|
</h1>
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="page-wrapper" tabindex="-1" role="main">
|
|
<div class="page-inner">
|
|
|
|
<section class="normal markdown-section">
|
|
|
|
<p align="center">
|
|
<img src="gopher.png" height="400">
|
|
</p><h1 align="center" id="
|
|
----go-patterns
|
|
----
|
|
----
|
|
----
|
|
----
|
|
--">
|
|
Go Patterns
|
|
<br>
|
|
<a href="http://travis-ci.org/tmrts/go-patterns" target="_blank"><img alt="build-status" src="https://img.shields.io/badge/build-passing-brightgreen.svg?style=flat-square"></a>
|
|
<a href="https://github.com/sindresorhus/awesome" target="_blank"><img alt="awesome" src="https://img.shields.io/badge/awesome-%E2%9C%93-ff69b4.svg?style=flat-square"></a>
|
|
<a href="https://github.com/tmrts/go-patterns/blob/master/LICENSE" target="_blank"><img alt="license" src="https://img.shields.io/badge/license-Apache%20License%202.0-E91E63.svg?style=flat-square"></a>
|
|
</h1>
|
|
<p></p>
|
|
|
|
<p>A curated collection of idiomatic design & application patterns for Go language.</p>
|
|
<h2 id="creational-patterns">Creational Patterns</h2>
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th style="text-align:center">Pattern</th>
|
|
<th style="text-align:left">Description</th>
|
|
<th style="text-align:center">Status</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td style="text-align:center"><a href="creational/abstract_factory.md">Abstract Factory</a></td>
|
|
<td style="text-align:left">Provides an interface for creating families of releated objects</td>
|
|
<td style="text-align:center">✘</td>
|
|
</tr>
|
|
<tr>
|
|
<td style="text-align:center"><a href="creational/builder.html">Builder</a></td>
|
|
<td style="text-align:left">Builds a complex object using simple objects</td>
|
|
<td style="text-align:center">✔</td>
|
|
</tr>
|
|
<tr>
|
|
<td style="text-align:center"><a href="creational/factory.html">Factory Method</a></td>
|
|
<td style="text-align:left">Defers instantiation of an object to a specialized function for creating instances</td>
|
|
<td style="text-align:center">✔</td>
|
|
</tr>
|
|
<tr>
|
|
<td style="text-align:center"><a href="creational/object-pool.html">Object Pool</a></td>
|
|
<td style="text-align:left">Instantiates and maintains a group of objects instances of the same type</td>
|
|
<td style="text-align:center">✔</td>
|
|
</tr>
|
|
<tr>
|
|
<td style="text-align:center"><a href="creational/singleton.html">Singleton</a></td>
|
|
<td style="text-align:left">Restricts instantiation of a type to one object</td>
|
|
<td style="text-align:center">✔</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
<h2 id="structural-patterns">Structural Patterns</h2>
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th style="text-align:center">Pattern</th>
|
|
<th style="text-align:left">Description</th>
|
|
<th style="text-align:center">Status</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td style="text-align:center"><a href="structural/bridge.md">Bridge</a></td>
|
|
<td style="text-align:left">Decouples an interface from its implementation so that the two can vary independently</td>
|
|
<td style="text-align:center">✘</td>
|
|
</tr>
|
|
<tr>
|
|
<td style="text-align:center"><a href="structural/composite.md">Composite</a></td>
|
|
<td style="text-align:left">Encapsulates and provides access to a number of different objects</td>
|
|
<td style="text-align:center">✘</td>
|
|
</tr>
|
|
<tr>
|
|
<td style="text-align:center"><a href="structural/decorator.html">Decorator</a></td>
|
|
<td style="text-align:left">Adds behavior to an object, statically or dynamically</td>
|
|
<td style="text-align:center">✔</td>
|
|
</tr>
|
|
<tr>
|
|
<td style="text-align:center"><a href="structural/facade.md">Facade</a></td>
|
|
<td style="text-align:left">Uses one type as an API to a number of others</td>
|
|
<td style="text-align:center">✘</td>
|
|
</tr>
|
|
<tr>
|
|
<td style="text-align:center"><a href="structural/flyweight.md">Flyweight</a></td>
|
|
<td style="text-align:left">Reuses existing instances of objects with similar/identical state to minimize resource usage</td>
|
|
<td style="text-align:center">✘</td>
|
|
</tr>
|
|
<tr>
|
|
<td style="text-align:center"><a href="structural/proxy.md">Proxy</a></td>
|
|
<td style="text-align:left">Provides a surrogate for an object to control it's actions</td>
|
|
<td style="text-align:center">✘</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
<h2 id="behavioral-patterns">Behavioral Patterns</h2>
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th style="text-align:center">Pattern</th>
|
|
<th style="text-align:left">Description</th>
|
|
<th style="text-align:center">Status</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td style="text-align:center"><a href="behavioral/chain_of_responsibility.md">Chain of Responsibility</a></td>
|
|
<td style="text-align:left">Avoids coupling a sender to receiver by giving more than object a chance to handle the request</td>
|
|
<td style="text-align:center">✘</td>
|
|
</tr>
|
|
<tr>
|
|
<td style="text-align:center"><a href="behavioral/command.md">Command</a></td>
|
|
<td style="text-align:left">Bundles a command and arguments to call later</td>
|
|
<td style="text-align:center">✘</td>
|
|
</tr>
|
|
<tr>
|
|
<td style="text-align:center"><a href="behavioral/mediator.md">Mediator</a></td>
|
|
<td style="text-align:left">Connects objects and acts as a proxy</td>
|
|
<td style="text-align:center">✘</td>
|
|
</tr>
|
|
<tr>
|
|
<td style="text-align:center"><a href="behavioral/memento.md">Memento</a></td>
|
|
<td style="text-align:left">Generate an opaque token that can be used to go back to a previous state</td>
|
|
<td style="text-align:center">✘</td>
|
|
</tr>
|
|
<tr>
|
|
<td style="text-align:center"><a href="behavioral/observer.html">Observer</a></td>
|
|
<td style="text-align:left">Provide a callback for notification of events/changes to data</td>
|
|
<td style="text-align:center">✔</td>
|
|
</tr>
|
|
<tr>
|
|
<td style="text-align:center"><a href="behavioral/registry.md">Registry</a></td>
|
|
<td style="text-align:left">Keep track of all subclasses of a given class</td>
|
|
<td style="text-align:center">✘</td>
|
|
</tr>
|
|
<tr>
|
|
<td style="text-align:center"><a href="behavioral/state.md">State</a></td>
|
|
<td style="text-align:left">Encapsulates varying behavior for the same object based on its internal state</td>
|
|
<td style="text-align:center">✘</td>
|
|
</tr>
|
|
<tr>
|
|
<td style="text-align:center"><a href="behavioral/strategy.html">Strategy</a></td>
|
|
<td style="text-align:left">Enables an algorithm's behavior to be selected at runtime</td>
|
|
<td style="text-align:center">✔</td>
|
|
</tr>
|
|
<tr>
|
|
<td style="text-align:center"><a href="behavioral/template.md">Template</a></td>
|
|
<td style="text-align:left">Defines a skeleton class which defers some methods to subclasses</td>
|
|
<td style="text-align:center">✘</td>
|
|
</tr>
|
|
<tr>
|
|
<td style="text-align:center"><a href="behavioral/visitor.md">Visitor</a></td>
|
|
<td style="text-align:left">Separates an algorithm from an object on which it operates</td>
|
|
<td style="text-align:center">✘</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
<h2 id="synchronization-patterns">Synchronization Patterns</h2>
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th style="text-align:center">Pattern</th>
|
|
<th style="text-align:left">Description</th>
|
|
<th style="text-align:center">Status</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td style="text-align:center"><a href="synchronization/condition_variable.md">Condition Variable</a></td>
|
|
<td style="text-align:left">Provides a mechanism for threads to temporarily give up access in order to wait for some condition</td>
|
|
<td style="text-align:center">✘</td>
|
|
</tr>
|
|
<tr>
|
|
<td style="text-align:center"><a href="synchronization/mutex.md">Lock/Mutex</a></td>
|
|
<td style="text-align:left">Enforces mutual exclusion limit on a resource to gain exclusive access</td>
|
|
<td style="text-align:center">✘</td>
|
|
</tr>
|
|
<tr>
|
|
<td style="text-align:center"><a href="synchronization/monitor.md">Monitor</a></td>
|
|
<td style="text-align:left">Combination of mutex and condition variable patterns</td>
|
|
<td style="text-align:center">✘</td>
|
|
</tr>
|
|
<tr>
|
|
<td style="text-align:center"><a href="synchronization/read_write_lock.md">Read-Write Lock</a></td>
|
|
<td style="text-align:left">Allows parallel read access, but only exclusive access on write operations to a resource</td>
|
|
<td style="text-align:center">✘</td>
|
|
</tr>
|
|
<tr>
|
|
<td style="text-align:center"><a href="synchronization/semaphore.html">Semaphore</a></td>
|
|
<td style="text-align:left">Allows controlling access to a common resource</td>
|
|
<td style="text-align:center">✔</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
<h2 id="concurrency-patterns">Concurrency Patterns</h2>
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th style="text-align:center">Pattern</th>
|
|
<th style="text-align:left">Description</th>
|
|
<th style="text-align:center">Status</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td style="text-align:center"><a href="concurrency/barrier.md">N-Barrier</a></td>
|
|
<td style="text-align:left">Prevents a process from proceeding until all N processes reach to the barrier</td>
|
|
<td style="text-align:center">✘</td>
|
|
</tr>
|
|
<tr>
|
|
<td style="text-align:center"><a href="concurrency/bounded_parallelism.html">Bounded Parallelism</a></td>
|
|
<td style="text-align:left">Completes large number of independent tasks with resource limits</td>
|
|
<td style="text-align:center">✔</td>
|
|
</tr>
|
|
<tr>
|
|
<td style="text-align:center"><a href="concurrency/broadcast.md">Broadcast</a></td>
|
|
<td style="text-align:left">Transfers a message to all recipients simultaneously</td>
|
|
<td style="text-align:center">✘</td>
|
|
</tr>
|
|
<tr>
|
|
<td style="text-align:center"><a href="concurrency/coroutine.md">Coroutines</a></td>
|
|
<td style="text-align:left">Subroutines that allow suspending and resuming execution at certain locations</td>
|
|
<td style="text-align:center">✘</td>
|
|
</tr>
|
|
<tr>
|
|
<td style="text-align:center"><a href="concurrency/generator.html">Generators</a></td>
|
|
<td style="text-align:left">Yields a sequence of values one at a time</td>
|
|
<td style="text-align:center">✔</td>
|
|
</tr>
|
|
<tr>
|
|
<td style="text-align:center"><a href="concurrency/reactor.md">Reactor</a></td>
|
|
<td style="text-align:left">Demultiplexes service requests delivered concurrently to a service handler and dispatches them syncronously to the associated request handlers</td>
|
|
<td style="text-align:center">✘</td>
|
|
</tr>
|
|
<tr>
|
|
<td style="text-align:center"><a href="concurrency/parallelism.html">Parallelism</a></td>
|
|
<td style="text-align:left">Completes large number of independent tasks</td>
|
|
<td style="text-align:center">✔</td>
|
|
</tr>
|
|
<tr>
|
|
<td style="text-align:center"><a href="concurrency/producer_consumer.md">Producer Consumer</a></td>
|
|
<td style="text-align:left">Separates tasks from task executions</td>
|
|
<td style="text-align:center">✘</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
<h2 id="messaging-patterns">Messaging Patterns</h2>
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th style="text-align:center">Pattern</th>
|
|
<th style="text-align:left">Description</th>
|
|
<th style="text-align:center">Status</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td style="text-align:center"><a href="messaging/fan_in.html">Fan-In</a></td>
|
|
<td style="text-align:left">Funnels tasks to a work sink (e.g. server)</td>
|
|
<td style="text-align:center">✔</td>
|
|
</tr>
|
|
<tr>
|
|
<td style="text-align:center"><a href="messaging/fan_out.html">Fan-Out</a></td>
|
|
<td style="text-align:left">Distributes tasks among workers (e.g. producer)</td>
|
|
<td style="text-align:center">✔</td>
|
|
</tr>
|
|
<tr>
|
|
<td style="text-align:center"><a href="messaging/futures_promises.md">Futures & Promises</a></td>
|
|
<td style="text-align:left">Acts as a place-holder of a result that is initially unknown for synchronization purposes</td>
|
|
<td style="text-align:center">✘</td>
|
|
</tr>
|
|
<tr>
|
|
<td style="text-align:center"><a href="messaging/publish_subscribe.html">Publish/Subscribe</a></td>
|
|
<td style="text-align:left">Passes information to a collection of recipients who subscribed to a topic</td>
|
|
<td style="text-align:center">✔</td>
|
|
</tr>
|
|
<tr>
|
|
<td style="text-align:center"><a href="messaging/push_pull.md">Push & Pull</a></td>
|
|
<td style="text-align:left">Distributes messages to multiple workers, arranged in a pipeline</td>
|
|
<td style="text-align:center">✘</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
<h2 id="stability-patterns">Stability Patterns</h2>
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th style="text-align:center">Pattern</th>
|
|
<th style="text-align:left">Description</th>
|
|
<th style="text-align:center">Status</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td style="text-align:center"><a href="stability/bulkhead.md">Bulkheads</a></td>
|
|
<td style="text-align:left">Enforces a principle of failure containment (i.e. prevents cascading failures)</td>
|
|
<td style="text-align:center">✘</td>
|
|
</tr>
|
|
<tr>
|
|
<td style="text-align:center"><a href="stability/circuit-breaker.html">Circuit-Breaker</a></td>
|
|
<td style="text-align:left">Stops the flow of the requests when requests are likely to fail</td>
|
|
<td style="text-align:center">✔</td>
|
|
</tr>
|
|
<tr>
|
|
<td style="text-align:center"><a href="stability/deadline.md">Deadline</a></td>
|
|
<td style="text-align:left">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)</td>
|
|
<td style="text-align:center">✘</td>
|
|
</tr>
|
|
<tr>
|
|
<td style="text-align:center"><a href="stability/fail_fast.md">Fail-Fast</a></td>
|
|
<td style="text-align:left">Checks the availability of required resources at the start of a request and fails if the requirements are not satisfied</td>
|
|
<td style="text-align:center">✘</td>
|
|
</tr>
|
|
<tr>
|
|
<td style="text-align:center"><a href="stability/handshaking.md">Handshaking</a></td>
|
|
<td style="text-align:left">Asks a component if it can take any more load, if it can't, the request is declined</td>
|
|
<td style="text-align:center">✘</td>
|
|
</tr>
|
|
<tr>
|
|
<td style="text-align:center"><a href="stability/steady_state.md">Steady-State</a></td>
|
|
<td style="text-align:left">For every service that accumulates a resource, some other service must recycle that resource</td>
|
|
<td style="text-align:center">✘</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
<h2 id="profiling-patterns">Profiling Patterns</h2>
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th style="text-align:center">Pattern</th>
|
|
<th style="text-align:left">Description</th>
|
|
<th style="text-align:center">Status</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td style="text-align:center"><a href="profiling/timing.html">Timing Functions</a></td>
|
|
<td style="text-align:left">Wraps a function and logs the execution</td>
|
|
<td style="text-align:center">✔</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
<h2 id="idioms">Idioms</h2>
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th style="text-align:center">Pattern</th>
|
|
<th style="text-align:left">Description</th>
|
|
<th style="text-align:center">Status</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td style="text-align:center"><a href="idiom/functional-options.html">Functional Options</a></td>
|
|
<td style="text-align:left">Allows creating clean APIs with sane defaults and idiomatic overrides</td>
|
|
<td style="text-align:center">✔</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
<h2 id="anti-patterns">Anti-Patterns</h2>
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th style="text-align:center">Pattern</th>
|
|
<th style="text-align:left">Description</th>
|
|
<th style="text-align:center">Status</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td style="text-align:center"><a href="anti-patterns/cascading_failures.md">Cascading Failures</a></td>
|
|
<td style="text-align:left">A failure in a system of interconnected parts in which the failure of a part causes a domino effect</td>
|
|
<td style="text-align:center">✘</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
|
|
|
|
</section>
|
|
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<a href="./#creational-patterns" class="navigation navigation-next navigation-unique" aria-label="Next page: Creational Patterns">
|
|
<i class="fa fa-angle-right"></i>
|
|
</a>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
<script>
|
|
var gitbook = gitbook || [];
|
|
gitbook.push(function() {
|
|
gitbook.page.hasChanged({"page":{"title":"Go Patterns","level":"1.1","depth":1,"next":{"title":"Creational Patterns","level":"1.1.1","depth":2,"anchor":"#creational-patterns","path":"README.md","ref":"README.md#creational-patterns","articles":[{"title":"Abstract Factory","level":"1.1.1.1","depth":3,"path":"creational/abstract_factory.md","ref":"creational/abstract_factory.md","articles":[]},{"title":"Builder","level":"1.1.1.2","depth":3,"path":"creational/builder.md","ref":"creational/builder.md","articles":[]},{"title":"Factory Method","level":"1.1.1.3","depth":3,"path":"creational/factory.md","ref":"creational/factory.md","articles":[]},{"title":"Object Pool","level":"1.1.1.4","depth":3,"path":"creational/object-pool.md","ref":"creational/object-pool.md","articles":[]},{"title":"Singleton","level":"1.1.1.5","depth":3,"path":"creational/singleton.md","ref":"creational/singleton.md","articles":[]}]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":["-search","-lunr","github","edit-link"],"pluginsConfig":{"github":{"url":"https://github.com/tmrts/go-patterns"},"edit-link":{"label":"","base":"https://github.com/tmrts/go-patterns/edit/master/"},"highlight":{},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"README.md","mtime":"2017-05-01T12:22:21.000Z","type":"markdown"},"gitbook":{"version":"3.2.2","time":"2017-05-01T12:23:41.783Z"},"basePath":".","book":{"language":""}});
|
|
});
|
|
</script>
|
|
</div>
|
|
|
|
|
|
<script src="gitbook/gitbook.js"></script>
|
|
<script src="gitbook/theme.js"></script>
|
|
|
|
|
|
<script src="gitbook/gitbook-plugin-github/plugin.js"></script>
|
|
|
|
|
|
|
|
<script src="gitbook/gitbook-plugin-edit-link/plugin.js"></script>
|
|
|
|
|
|
|
|
<script src="gitbook/gitbook-plugin-sharing/buttons.js"></script>
|
|
|
|
|
|
|
|
<script src="gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
|
|
|
|
|
|
|
|
</body>
|
|
</html>
|
|
|