Design Patterns

🧷:go-design-patterns

Creational Pattern

Factory Method 工場パターン

Provides an interface for creating objects in a superclass, but allows subclasses to alter the type of objects that will be created.

(おや) クラスでオブジェクトを生成(せいせい) するためのインターフェースを提供(ていきょう) しますが、サブクラスが生成(せいせい) されるオブジェクトの(かた)変更(へんこう) できるようにします。

Abstract Factory 抽象工場

Lets you produce families of related objects without specifying their concrete classes.

具体的(ぐたいてき) なクラスを指定(してい) せずに、関連(かんれん) するオブジェクトのファミリーを生成(せいせい) できます。

Builder ビルダーパターン

Lets you construct complex objects step by step. The pattern allows you to produce different types and representations of an object using the same construction code.

複雑(ふくざつ) なオブジェクトを段階的(だんかいてき)構築(こうちく) できます。このパターンにより、(おな)構築(こうちく) コードを使用(しよう) して、(こと) なる(かた)表現(ひょうげん) のオブジェクトを生成(せいせい) できます。

Prototype プロトタイプパターン

Lets you copy existing objects without making your code dependent on their classes.

インスタンス() せずに既存(きそん) のオブジェクトをコピーして(あたら) しいオブジェクトを生成(せいせい) できます。このパターンにより、既存(きそん) のオブジェクトの状態(じょうたい) をコピーして(あたら) しいオブジェクトを作成(さくせい) できます。

Singleton シングルトンパターン

Lets you ensure that a class has only one instance, while providing a global access point to this instance.

クラスが唯一(ゆいいつ) のインスタンスのみを() つことを保証(ほしょう) し、そのインスタンスへのグローバルアクセスポイントを提供(ていきょう) します。

Structural Pattern

Adapter アダプターパターン

Allows objects with incompatible interfaces to collaborate.

互換性(ごかんせい) のないインターフェースを() つオブジェクト(かん)連携(れんけい)可能(かのう) にします。
  ---
title: Go Adapter Example
---
classDiagram

    class XMLData {

    }

    class JSONData {

    }

    class XMLService {
        +ParseXML(xmlData []byte)
    }

    class XMLToJSONAdapter {
        -xmlService *XMLService
        +ConvertToJSON(xml []byte)
    }

    class Client {
        -xmlService *XMLService
        -xmlToJSONAdapter *XMLToJSONAdapter
        +ProcessXMLData(data []byte)
        +ProcessJSONData(data []byte)
    }

    XMLService *.. XMLToJSONAdapter
    XMLService ..> XMLData
    XMLToJSONAdapter ..> JSONData
    Client ..* XMLToJSONAdapter
    Client ..* XMLService

Bridge ブリッジパターン

Lets you split a large class or a set of closely related classes into two separate hierarchies—abstraction and implementation—which can be developed independently of each other.

(おお) きなクラスまたは密接(みっせつ)関連(かんれん) するクラスのセットを、抽象化(ちゅうしょうか)実装(じっそう) という2つの独立(どくりつ) した階層(かいそう)分割(ぶんかつ) します。これらの階層(かいそう)独立(どくりつ) して開発(かいはつ) できます。

Composite コンポジットパターン

Lets you compose objects into tree structures and then work with these structures as if they were individual objects.

オブジェクトを() 構造(こうぞう)()() わせ、それらの構造(こうぞう)個々(ここ) のオブジェクトのように(あつか) うことができます。

Decorator デコレーターパターン

Lets you attach new behaviors to objects by placing these objects inside special wrapper objects that contain the behaviors.

オブジェクトを特別(とくべつ) なラッパーオブジェクトの(なか)配置(はいち) することで、(あたら) しい()() いを追加(ついか) できます。

Facade ファサードパターン

Provides a simplified interface to a library, a framework, or any other complex set of classes.

ライブラリ、フレームワーク、または複雑(ふくざつ) なクラスのセットに(たい) して、簡素化(かんそか) されたインターフェースを提供(ていきょう) します。

Flyweight フライウェイトパターン

Lets you fit more objects into the available amount of RAM by sharing common parts of state between multiple objects instead of keeping all of the data in each object.

(かく) オブジェクトにすべてのデータを保持(ほじ) する() わりに、複数(ふくすう) のオブジェクト(かん)共通(きょうつう)状態(じょうたい) 部分(ぶぶん)共有(きょうゆう) することで、利用可能(りようかのう) なメモリをより効率的(こうりつてき)使用(しよう) できます。

Proxy プロキシパターン

Lets you provide a substitute or placeholder for another object. A proxy controls access to the original object, allowing you to perform something either before or after the request gets through to the original object.

(べつ) のオブジェクトの代替(だいたい) またはプレースホルダーを提供(ていきょう) します。プロキシは(もと) のオブジェクトへのアクセスを制御(せいぎょ) し、リクエストが(もと) のオブジェクトに(とど)(まえ) または(あと)(なに) かを実行(じっこう) できます。

Behavior Pattern

Observer オブザーバーパターン

Lets you define a subscription mechanism to notify multiple objects about any events that happen to the object they’re observing.

購読(こうどく) メカニズムを定義(ていぎ) し、観察(かんさつ) しているオブジェクトに発生(はっせい) したイベントを複数(ふくすう) のオブジェクトに通知(つうち) できます。

Strategy ストラテジーパターン

Lets you define a family of algorithms, put each of them into a separate class, and make their objects interchangeable.

アルゴリズムのファミリーを定義(ていぎ) し、それぞれを別々(べつべつ) のクラスに配置(はいち) し、それらのオブジェクトを相互(そうご)交換可能(こうかんかのう) にします。

Chain of Responsibility 責任連鎖パターン

Lets you pass requests along a chain of handlers. Upon receiving a request, each handler decides either to process the request or to pass it to the next handler in the chain.

リクエストをハンドラーの連鎖(れんさ)沿() って(わた) すことができます。(かく) ハンドラーはリクエストを()() ると、リクエストを処理(しょり) するか、連鎖(れんさ)(つぎ) のハンドラーに(わた) すかを決定(けってい) します。

Command コマンドパターン

Turns a request into a stand-alone object that contains all information about the request. This transformation lets you pass requests as a method arguments, delay or queue a request’s execution, and support undoable operations.

リクエストを独立(どくりつ) したオブジェクトに変換(へんかん) し、リクエストに(かん) するすべての情報(じょうほう)(ふく) みます。この変換(へんかん) により、リクエストをメソッド引数(ひきすう) として(わた) したり、リクエストの実行(じっこう)遅延(ちえん) またはキューに() れたり、()()可能(かのう)操作(そうさ) をサポートしたりできます。

Iterator イテレーターパターン

Lets you traverse elements of a collection without exposing its underlying representation (list, stack, tree, etc.).

コレクションの基盤(きばん) となる表現(ひょうげん) (リスト、スタック、() など)を公開(こうかい) せずに、要素(ようそ)走査(そうさ) できます。

Mediator メディエーターパターン

Lets you reduce chaotic dependencies between objects. The pattern restricts direct communications between the objects and forces them to collaborate only via a mediator object.

オブジェクト(かん)混乱(こんらん) した依存関係(いぞんかんけい)() らすことができます。このパターンはオブジェクト(かん)直接的(ちょくせつてき)通信(つうしん)制限(せいげん) し、メディエーターオブジェクトを(かい) してのみ連携(れんけい) するように強制(きょうせい) します。

Memento メメントパターン

Lets you save and restore the previous state of an object without revealing the details of its implementation.

実装(じっそう)詳細(しょうさい)() かさずに、オブジェクトの以前(いぜん)状態(じょうたい)保存(ほぞん) および復元(ふくげん) できます。

State ステートパターン

Lets an object alter its behavior when its internal state changes. It appears as if the object changed its class.

オブジェクトの内部(ないぶ) 状態(じょうたい)変化(へんか) したときに、その()() いを変更(へんこう) できます。オブジェクトのクラスが() わったかのように() えます。

Template Method テンプレートメソッドパターン

Defines the skeleton of an algorithm in the superclass but lets subclasses override specific steps of the algorithm without changing its structure.

(おや) クラスでアルゴリズムの骨格(こっかく)定義(ていぎ) しますが、サブクラスがアルゴリズムの構造(こうぞう)変更(へんこう) せずに特定(とくてい) のステップをオーバーライドできるようにします。

Visitor ビジターパターン

Lets you separate algorithms from the objects on which they operate.

アルゴリズムとそれが操作(そうさ) するオブジェクトを分離(ぶんり) できます。

Interpreter インタープリターパターン

Given a language, define a representation for its grammar along with an interpreter that uses the representation to interpret sentences in the language.

言語(げんご)(あた) えられたら、その文法(ぶんぽう)表現(ひょうげん)定義(ていぎ) し、その表現(ひょうげん)使用(しよう) して言語(げんご)(ぶん)解釈(かいしゃく) するインタープリターを提供(ていきょう) します。