Abstract_Factory_パターン
[Wikipedia|▼Menu]

Abstract Factory パターン(アブストラクト・ファクトリ・パターン)[1]とは、GoF(Gang of Four; 4人のギャングたち)によって定義されたデザインパターンの1つである。関連するインスタンス群を生成するための API を集約することによって、利用側がインスタンス群をまとめて変えられるようにし、さらに組み合わせ方を間違えないようにする[1]。日本語では「抽象的な工場」と翻訳される事が多い。

Kit パターンとも呼ばれる[1]
クラス図

Abstract Factory パターンのクラス図を以下に挙げる。Product1, Product2 は抽象クラスであり、ConcreteProduct1, ConcreteProduct2 はそれぞれを継承した具象クラスである。抽象クラス AbstractFactory は、抽象クラス Product1, Product2 を生成するメソッドを持つ。クラス ConcreteFactory は AbstractFactory を継承し、具象クラス ConcreteProduct1, ConcreteProduct2 を生成するメソッドを持つ。ClientクラスはAbstractFactoryのインターフェースを通じて、ConcreteFactoryのインスタンスを使い、ConcreteProduct1や2のインスタンスを得る。ClientクラスはProduct1や2のインターフェースを通じてConcreteProduct1や2のインスタンスを利用する
利用例.mw-parser-output .ambox{border:1px solid #a2a9b1;border-left:10px solid #36c;background-color:#fbfbfb;box-sizing:border-box}.mw-parser-output .ambox+link+.ambox,.mw-parser-output .ambox+link+style+.ambox,.mw-parser-output .ambox+link+link+.ambox,.mw-parser-output .ambox+.mw-empty-elt+link+.ambox,.mw-parser-output .ambox+.mw-empty-elt+link+style+.ambox,.mw-parser-output .ambox+.mw-empty-elt+link+link+.ambox{margin-top:-1px}html body.mediawiki .mw-parser-output .ambox.mbox-small-left{margin:4px 1em 4px 0;overflow:hidden;width:238px;border-collapse:collapse;font-size:88%;line-height:1.25em}.mw-parser-output .ambox-speedy{border-left:10px solid #b32424;background-color:#fee7e6}.mw-parser-output .ambox-delete{border-left:10px solid #b32424}.mw-parser-output .ambox-content{border-left:10px solid #f28500}.mw-parser-output .ambox-style{border-left:10px solid #fc3}.mw-parser-output .ambox-move{border-left:10px solid #9932cc}.mw-parser-output .ambox-protection{border-left:10px solid #a2a9b1}.mw-parser-output .ambox .mbox-text{border:none;padding:0.25em 0.5em;width:100%;font-size:90%}.mw-parser-output .ambox .mbox-image{border:none;padding:2px 0 2px 0.5em;text-align:center}.mw-parser-output .ambox .mbox-imageright{border:none;padding:2px 0.5em 2px 0;text-align:center}.mw-parser-output .ambox .mbox-empty-cell{border:none;padding:0;width:1px}.mw-parser-output .ambox .mbox-image-div{width:52px}html.client-js body.skin-minerva .mw-parser-output .mbox-text-span{margin-left:23px!important}@media(min-width:720px){.mw-parser-output .ambox{margin:0 10%}}

この節の加筆が望まれています。

応用例

DOM は Abstract Factory パターンを応用した API の一つである。参考までに、クラス図との対応関係を示す。
AbstractFactory
org.w3c.dom.Document
AbstractFactory#createProduct()
org.w3c.dom.Document#createElement(String), ⇒org.w3c.dom.Document#createTextNode(String) など
Product
org.w3c.dom.Element, ⇒org.w3c.dom.Text など
関連するパターン

生成するProductを変更する手法としては、AbstractFactoryクラスがfactory method(Factory Method パターンを参照)を持ち、それを個々のConcreteFactoryが上書きする手法が一般的である。しかし、Prototype パターンを使い、prototypeとなるオブジェクトの変更により生成するProductを変える手法もある[1]

ConcreteFactoryは、singletonオブジェクト(Singleton パターンを参照)であることもある。
Factory Method パターンとの違い

『オブジェクト指向における再利用のためのデザインパターン』においてはFactory Method パターンは「クラスパターン」に分類されている。一方Abstract Factory パターンは「オブジェクトパターン」に分類されている。

Factory Method パターンは親クラスであるCreatorクラスが子クラスであるConcreteCreatorクラスにオブジェクトの生成を委ねるという、CreatorクラスとConcreteCreatorクラスとの関連である。一方でAbstract Factory パターンは、ClientのインスタンスがConcreteFactoryのインスタンスにオブジェクトの生成を委ねるという、オブジェクト同士の関連である。
関連項目

Factory Method パターン

Prototype パターン

デザインパターン

Document Object Model

参考文献^ a b c d エリック・ガンマラルフ・ジョンソンリチャード・ヘルムジョン・ブリシディース(著)、グラディ・ブーチ(まえがき)、本位田真一、吉田和樹(監訳)、『オブジェクト指向における再利用のためのデザインパターン』、ソフトバンクパブリッシング、1995。ISBN 978-4-7973-1112-9.










デザインパターン
GoFによる23種のパターン

生成に関するパターン

Abstract factory

Builder

Factory method

Prototype

Singleton

構造に関するパターン

Adapter

Bridge

Composite

Decorator

Facade

Flyweight

Proxy

振る舞いに関するパターン

Chain of responsibility

Command

Interpreter

Iterator

Mediator

Memento

Observer

State

Strategy

Template method

Visitor


並行性に関するパターン

Active object(英語版)

Balking(英語版)

Double-checked locking(英語版)

Event-based asynchronous(英語版)

Guarded suspension(英語版)

Join(英語版)

ロック

モニタ

Proactor(英語版)

Reactor

Readers?writer lock(英語版)

Scheduler(英語版)

Thread pool(英語版)

スレッド局所記憶

アーキテクチャに関するパターン

Front Controller(英語版)

Interceptor(英語版)

MVC

MVVM

多層アーキテクチャ

Specification(英語版)

出版-購読型モデル

Naked objects(英語版)

Service Locator(英語版)

Active Record

Identity map(英語版)

Data Access Object

Data Transfer Object

その他のパターン

依存性の注入 (DI)

遅延読み込み


次ページ
記事の検索
おまかせリスト
▼オプションを表示
ブックマーク登録
mixiチェック!
Twitterに投稿
オプション/リンク一覧
話題のニュース
列車運行情報
暇つぶしWikipedia

Size:15 KB
出典: フリー百科事典『ウィキペディア(Wikipedia)
担当:undef