SlideShare a Scribd company logo
1 of 23
Download to read offline
Design Pattern
                         Abstract



                   ●   Kazunori Ishikawa (Makai)



2nt October 2011           Design Pattern : Abstract
                                                       1
Backgrounds



      「前にもこんな感じのコード書いたなあ.
      でも前のコードは,今回は使えないなあ.
      なぜなら,前のコードを修正するよりも
      一から書いた方が速いし.」




2nt October 2011   Design Pattern : Abstract
                                               2
Backgrounds




                   MOTTAINAI !!




2nt October 2011     Design Pattern : Abstract
                                                 3
Backgrounds


                達人は
         多くの経験から課題をパターン化し,
      新たな課題をそのパターンに当てはめて解決する.
            だから生産性が高い.
            プログラミングも同様.




2nt October 2011   Design Pattern : Abstract
                                               4
Backgrounds

     ●   Object指向言語のプログラムを機能や役割で見る
         と,幾つかのパターンに分けることができる
         ●   複数の要素が集まっている中から1つ1つ取り出して利
             用するパターン
         ●   現在の状態を保存し,必要に応じてUndoするパターン
             ...etc


               GoFが23のパターンにまとめたよ!
    ※ GoF (Gang of Four) :
       エーリヒ・ガンマ、リチャード・ヘルム、ラルフ・ジョンソン、ジョン・ブリシディースの四人組


2nt October 2011      Design Pattern : Abstract
                                                      5
Backgrounds

     ●   関連:パターン・ランゲージ
         ●   人々が「心地よい」と感じる環境(都市、建築物)を
             分析して、253のパターンを挙げた。
             パターンが集まり、それらの関連の中で環境が
             形づくられる。
             –   「小さな人だまり」「座れる階段」
                 「街路を見下ろすバルコニー」など
         ●   家を建てたり、まちづくりのルールを決める際に
             役立つヒント
         ●   これらのパターンは各国の美しい街や住まいに共通する
             普遍的なもの
         ●   急激な近代化の中で忘れられてしまった


2nt October 2011         Design Pattern : Abstract
                                                     6
Aim



                   ●   プログラムを再利用可能にすること
                       ●   拡張しやすいプログラムを作ること




2nt October 2011              Design Pattern : Abstract
                                                          7
Abstract



                   ●   プログラムを完成品として見ない
                       ●   拡張して使うことを前提として設計

                   ●   23の設計パターン
                       ●   モジュールの役割に応じたパターン




2nt October 2011             Design Pattern : Abstract
                                                         8
Design Pattern enables...

     ●   拡張性の高いプログラムを設計できる
         ●   一般化された設計

     ●   プログラムの構造の比較を容易にし,
         議論を容易にする

     ●   プログラムの役割を明確にする
         ●   モジュール/パッケージ/クラス




2nt October 2011      Design Pattern : Abstract
                                                  9
23 Patterns

2nt October 2011   Design Pattern : Abstract
                                               10
23 Patterns

     ●   パターンのパターン (DP数)
             –     比較的簡単なDP (2)
             –     クラス継承関連DP (2)
             –     インスタンス作成関連DP (4)
             –     分けて考えるDP (2)
             –     同一視DP (2)
             –     構造を渡り歩くDP (2)
             –     シンプル化DP (2)
             –     状態管理DP (3)
             –     効率化DP (2)
             –     意外なものをクラスで表現DP (2)


2nt October 2011           Design Pattern : Abstract
                                                       11
比較的簡単なDP

     ●
         Iterator
         ●   複数の要素の集合から,
             1つずつ取り出して利用

     ●
         Adapter
         ●   異なるインタフェースを持つクラスの間に噛ませ,
             橋渡しの役割を担当




2nt October 2011    Design Pattern : Abstract
                                                12
クラス継承関係DP

     ●
         Template Method
         ●   スーパークラスで処理の骨組みを記述し,
             サブクラスで具体的な処理を記述

     ●
         Factory Method
         ●   スーパークラスでインスタンス作成の骨組みを記述し,
             サブクラスで具体的な作成法を記述




2nt October 2011    Design Pattern : Abstract
                                                13
インスタンス作成関連DP

    ●
        Singleton
        ●   インスタンスを1つしか作らない,
            インスタンスは1つのみで十分
    ●
        Prototype
        ●   雛形となるインスタンスを作成し,
            それをコピーすることでより具体的なインスタンスを作成
    ●
        Builder
        ●   複雑なインスタンスを,段階を踏んで作成
    ●
        Abstract Factory
        ●   部品を組み合わせてインスタンスを作成


2nt October 2011      Design Pattern : Abstract
                                                  14
分けて考えるDP

     ●
         Bridge
         ●   機能の階層と実装の階層に分け,
             その間を橋渡し

     ●
         Strategy
         ●   アルゴリズムを切り替えて,改良を容易に




2nt October 2011    Design Pattern : Abstract
                                                15
同一視DP

         異なるものを統一的に利用,
         インタフェースを変えずに機能を追加

     ●
         Composite
         ●   容器と中身を同一視し,再帰的な構造を作成

     ●
         Decorator
         ●   「飾り」と中身を同一視
             → 飾りを何重にも重ねる


2nt October 2011     Design Pattern : Abstract
                                                 16
構造を渡り歩くDP

     ●
         Visitor
         ●   構造を渡り歩きながら,同じ処理を繰り返す

     ●
         Chain of Responsibility
         ●   構造を渡り歩き,そのどこかで処理(たらい回し)




2nt October 2011     Design Pattern : Abstract
                                                 17
シンプル化DP

     ●
         Facade(ファサード)
         ●   窓口役のクラスをつくり,
             そいつを通してシステム全体の操作

     ●
         Mediator
         ●   複数クラスが互いにやりとりを行うのではなく,
             相談役(仲介役)を設けてそいつとだけやり取り




2nt October 2011    Design Pattern : Abstract
                                                18
状態管理DP

     ●
         Observer
         ●   状態が変化するクラスと,
             その変化を受け取るクラスに分割

     ●
         Memento
         ●   現在の状態を保存し,必要に応じて復帰

     ●
         State
         ●   状態をクラスで表現
             状態に応じたswitch文を減らす


2nt October 2011      Design Pattern : Abstract
                                                  19
効率化DP

     ●
         Flyweight
         ●   複数箇所で同じもの(処理)が現れるとき,
             それらを共有する

     ●
         Proxy
         ●   必要なものが必要になるまで作成せず,
             それまでは代理のものを利用する




2nt October 2011     Design Pattern : Abstract
                                                 20
意外なものをクラス化DP

     ●
         Command
         ●   要求・命令をクラスで表現

     ●
         Interpreter
         ●   文法規則をクラスで表現




2nt October 2011       Design Pattern : Abstract
                                                   21
Enquete

    ●   比較的簡単                                ●   構造を渡り歩く
        ●   Iterator                             ●   Visitor
        ●   Adapter                              ●   Chain of Responsibility
    ●   クラス継承関連                              ●   シンプル化
            Template Method
        ●
                                                 ●   Facade
            Factory Method
                                                     Mediator
        ●
                                                 ●

        インスタンス作成関連
                                                 状態管理
    ●
                                             ●
        ●   Singleton
                                                 ●   Observer
        ●   Prototype
                                                 ●   Memento
        ●   Builder
                                                 ●   State
        ●   Abstract Factory
                                             ●   効率化
    ●   分けて考える
            Bridge
                                                 ●   Flyweight
        ●



        ●   Strategy                             ●   Proxy

    ●   同一視                                  ●   意外なものをクラスで表現
        ●   Composite                            ●   Command
        ●   Decorator                            ●   Interpreter




2nt October 2011               Design Pattern : Abstract
                                                                               22
2nt October 2011   Design Pattern : Abstract
                                               23

More Related Content

Similar to Abstract

Frameworks We Live By: Design by day-to-day framework development: Multi-para...
Frameworks We Live By: Design by day-to-day framework development: Multi-para...Frameworks We Live By: Design by day-to-day framework development: Multi-para...
Frameworks We Live By: Design by day-to-day framework development: Multi-para...
Atsuhiro Kubo
 
Python3 プログラミング勉強会
Python3 プログラミング勉強会Python3 プログラミング勉強会
Python3 プログラミング勉強会
Tetsuya Morimoto
 
XP祭り2010「アジャイルUXの潮流」
XP祭り2010「アジャイルUXの潮流」XP祭り2010「アジャイルUXの潮流」
XP祭り2010「アジャイルUXの潮流」
Tarumoto Tetsuya
 

Similar to Abstract (20)

設計/コンポーネント設計(3) 【クラウドアプリケーションのためのオブジェクト指向分析設計講座 第22回】
設計/コンポーネント設計(3) 【クラウドアプリケーションのためのオブジェクト指向分析設計講座 第22回】設計/コンポーネント設計(3) 【クラウドアプリケーションのためのオブジェクト指向分析設計講座 第22回】
設計/コンポーネント設計(3) 【クラウドアプリケーションのためのオブジェクト指向分析設計講座 第22回】
 
Why-is-ImplementationPattterns-important-so-much
Why-is-ImplementationPattterns-important-so-muchWhy-is-ImplementationPattterns-important-so-much
Why-is-ImplementationPattterns-important-so-much
 
設計/ドメイン設計(4) 【クラウドアプリケーションのためのオブジェクト指向分析設計講座 第26回】
設計/ドメイン設計(4) 【クラウドアプリケーションのためのオブジェクト指向分析設計講座 第26回】設計/ドメイン設計(4) 【クラウドアプリケーションのためのオブジェクト指向分析設計講座 第26回】
設計/ドメイン設計(4) 【クラウドアプリケーションのためのオブジェクト指向分析設計講座 第26回】
 
ユーザーストーリーワークショップ実践編
ユーザーストーリーワークショップ実践編ユーザーストーリーワークショップ実践編
ユーザーストーリーワークショップ実践編
 
LibreOffice Conference 2022 (ミラノ)参加報告
LibreOffice Conference 2022 (ミラノ)参加報告LibreOffice Conference 2022 (ミラノ)参加報告
LibreOffice Conference 2022 (ミラノ)参加報告
 
Frameworks We Live By: Design by day-to-day framework development: Multi-para...
Frameworks We Live By: Design by day-to-day framework development: Multi-para...Frameworks We Live By: Design by day-to-day framework development: Multi-para...
Frameworks We Live By: Design by day-to-day framework development: Multi-para...
 
Reactnative はじめの一歩
Reactnative はじめの一歩Reactnative はじめの一歩
Reactnative はじめの一歩
 
Programming camp code reading
Programming camp code readingProgramming camp code reading
Programming camp code reading
 
Python3 プログラミング勉強会
Python3 プログラミング勉強会Python3 プログラミング勉強会
Python3 プログラミング勉強会
 
[NAACL2018読み会] Deep Communicating Agents for Abstractive Summarization
[NAACL2018読み会] Deep Communicating Agents for Abstractive Summarization[NAACL2018読み会] Deep Communicating Agents for Abstractive Summarization
[NAACL2018読み会] Deep Communicating Agents for Abstractive Summarization
 
XP祭り2010「アジャイルUXの潮流」
XP祭り2010「アジャイルUXの潮流」XP祭り2010「アジャイルUXの潮流」
XP祭り2010「アジャイルUXの潮流」
 
LightSwitch で遊んでみた Rev. 2
LightSwitch で遊んでみた Rev. 2LightSwitch で遊んでみた Rev. 2
LightSwitch で遊んでみた Rev. 2
 
3週連続DDDその3 ドメイン駆動設計 戦略的設計
3週連続DDDその3  ドメイン駆動設計 戦略的設計3週連続DDDその3  ドメイン駆動設計 戦略的設計
3週連続DDDその3 ドメイン駆動設計 戦略的設計
 
最先端NLP勉強会2017_ACL17
最先端NLP勉強会2017_ACL17最先端NLP勉強会2017_ACL17
最先端NLP勉強会2017_ACL17
 
設計 【クラウドアプリケーションのためのオブジェクト指向分析設計講座 第18回】
設計 【クラウドアプリケーションのためのオブジェクト指向分析設計講座 第18回】設計 【クラウドアプリケーションのためのオブジェクト指向分析設計講座 第18回】
設計 【クラウドアプリケーションのためのオブジェクト指向分析設計講座 第18回】
 
Distributed Agile using UML
Distributed Agile using UMLDistributed Agile using UML
Distributed Agile using UML
 
The pragmatic programing 2.10 2.13
The pragmatic programing 2.10   2.13The pragmatic programing 2.10   2.13
The pragmatic programing 2.10 2.13
 
[DL輪読会]Convolutional Sequence to Sequence Learning
[DL輪読会]Convolutional Sequence to Sequence Learning[DL輪読会]Convolutional Sequence to Sequence Learning
[DL輪読会]Convolutional Sequence to Sequence Learning
 
introduction to Marionette.js (jscafe14)
introduction to Marionette.js (jscafe14)introduction to Marionette.js (jscafe14)
introduction to Marionette.js (jscafe14)
 
論文紹介:Video Task Decathlon: Unifying Image and Video Tasks in Autonomous Driving
論文紹介:Video Task Decathlon: Unifying Image and Video Tasks in Autonomous Driving論文紹介:Video Task Decathlon: Unifying Image and Video Tasks in Autonomous Driving
論文紹介:Video Task Decathlon: Unifying Image and Video Tasks in Autonomous Driving
 

Abstract

  • 1. Design Pattern Abstract ● Kazunori Ishikawa (Makai) 2nt October 2011 Design Pattern : Abstract 1
  • 2. Backgrounds 「前にもこんな感じのコード書いたなあ. でも前のコードは,今回は使えないなあ. なぜなら,前のコードを修正するよりも 一から書いた方が速いし.」 2nt October 2011 Design Pattern : Abstract 2
  • 3. Backgrounds MOTTAINAI !! 2nt October 2011 Design Pattern : Abstract 3
  • 4. Backgrounds 達人は 多くの経験から課題をパターン化し, 新たな課題をそのパターンに当てはめて解決する. だから生産性が高い. プログラミングも同様. 2nt October 2011 Design Pattern : Abstract 4
  • 5. Backgrounds ● Object指向言語のプログラムを機能や役割で見る と,幾つかのパターンに分けることができる ● 複数の要素が集まっている中から1つ1つ取り出して利 用するパターン ● 現在の状態を保存し,必要に応じてUndoするパターン ...etc GoFが23のパターンにまとめたよ! ※ GoF (Gang of Four) : エーリヒ・ガンマ、リチャード・ヘルム、ラルフ・ジョンソン、ジョン・ブリシディースの四人組 2nt October 2011 Design Pattern : Abstract 5
  • 6. Backgrounds ● 関連:パターン・ランゲージ ● 人々が「心地よい」と感じる環境(都市、建築物)を 分析して、253のパターンを挙げた。 パターンが集まり、それらの関連の中で環境が 形づくられる。 – 「小さな人だまり」「座れる階段」 「街路を見下ろすバルコニー」など ● 家を建てたり、まちづくりのルールを決める際に 役立つヒント ● これらのパターンは各国の美しい街や住まいに共通する 普遍的なもの ● 急激な近代化の中で忘れられてしまった 2nt October 2011 Design Pattern : Abstract 6
  • 7. Aim ● プログラムを再利用可能にすること ● 拡張しやすいプログラムを作ること 2nt October 2011 Design Pattern : Abstract 7
  • 8. Abstract ● プログラムを完成品として見ない ● 拡張して使うことを前提として設計 ● 23の設計パターン ● モジュールの役割に応じたパターン 2nt October 2011 Design Pattern : Abstract 8
  • 9. Design Pattern enables... ● 拡張性の高いプログラムを設計できる ● 一般化された設計 ● プログラムの構造の比較を容易にし, 議論を容易にする ● プログラムの役割を明確にする ● モジュール/パッケージ/クラス 2nt October 2011 Design Pattern : Abstract 9
  • 10. 23 Patterns 2nt October 2011 Design Pattern : Abstract 10
  • 11. 23 Patterns ● パターンのパターン (DP数) – 比較的簡単なDP (2) – クラス継承関連DP (2) – インスタンス作成関連DP (4) – 分けて考えるDP (2) – 同一視DP (2) – 構造を渡り歩くDP (2) – シンプル化DP (2) – 状態管理DP (3) – 効率化DP (2) – 意外なものをクラスで表現DP (2) 2nt October 2011 Design Pattern : Abstract 11
  • 12. 比較的簡単なDP ● Iterator ● 複数の要素の集合から, 1つずつ取り出して利用 ● Adapter ● 異なるインタフェースを持つクラスの間に噛ませ, 橋渡しの役割を担当 2nt October 2011 Design Pattern : Abstract 12
  • 13. クラス継承関係DP ● Template Method ● スーパークラスで処理の骨組みを記述し, サブクラスで具体的な処理を記述 ● Factory Method ● スーパークラスでインスタンス作成の骨組みを記述し, サブクラスで具体的な作成法を記述 2nt October 2011 Design Pattern : Abstract 13
  • 14. インスタンス作成関連DP ● Singleton ● インスタンスを1つしか作らない, インスタンスは1つのみで十分 ● Prototype ● 雛形となるインスタンスを作成し, それをコピーすることでより具体的なインスタンスを作成 ● Builder ● 複雑なインスタンスを,段階を踏んで作成 ● Abstract Factory ● 部品を組み合わせてインスタンスを作成 2nt October 2011 Design Pattern : Abstract 14
  • 15. 分けて考えるDP ● Bridge ● 機能の階層と実装の階層に分け, その間を橋渡し ● Strategy ● アルゴリズムを切り替えて,改良を容易に 2nt October 2011 Design Pattern : Abstract 15
  • 16. 同一視DP 異なるものを統一的に利用, インタフェースを変えずに機能を追加 ● Composite ● 容器と中身を同一視し,再帰的な構造を作成 ● Decorator ● 「飾り」と中身を同一視 → 飾りを何重にも重ねる 2nt October 2011 Design Pattern : Abstract 16
  • 17. 構造を渡り歩くDP ● Visitor ● 構造を渡り歩きながら,同じ処理を繰り返す ● Chain of Responsibility ● 構造を渡り歩き,そのどこかで処理(たらい回し) 2nt October 2011 Design Pattern : Abstract 17
  • 18. シンプル化DP ● Facade(ファサード) ● 窓口役のクラスをつくり, そいつを通してシステム全体の操作 ● Mediator ● 複数クラスが互いにやりとりを行うのではなく, 相談役(仲介役)を設けてそいつとだけやり取り 2nt October 2011 Design Pattern : Abstract 18
  • 19. 状態管理DP ● Observer ● 状態が変化するクラスと, その変化を受け取るクラスに分割 ● Memento ● 現在の状態を保存し,必要に応じて復帰 ● State ● 状態をクラスで表現 状態に応じたswitch文を減らす 2nt October 2011 Design Pattern : Abstract 19
  • 20. 効率化DP ● Flyweight ● 複数箇所で同じもの(処理)が現れるとき, それらを共有する ● Proxy ● 必要なものが必要になるまで作成せず, それまでは代理のものを利用する 2nt October 2011 Design Pattern : Abstract 20
  • 21. 意外なものをクラス化DP ● Command ● 要求・命令をクラスで表現 ● Interpreter ● 文法規則をクラスで表現 2nt October 2011 Design Pattern : Abstract 21
  • 22. Enquete ● 比較的簡単 ● 構造を渡り歩く ● Iterator ● Visitor ● Adapter ● Chain of Responsibility ● クラス継承関連 ● シンプル化 Template Method ● ● Facade Factory Method Mediator ● ● インスタンス作成関連 状態管理 ● ● ● Singleton ● Observer ● Prototype ● Memento ● Builder ● State ● Abstract Factory ● 効率化 ● 分けて考える Bridge ● Flyweight ● ● Strategy ● Proxy ● 同一視 ● 意外なものをクラスで表現 ● Composite ● Command ● Decorator ● Interpreter 2nt October 2011 Design Pattern : Abstract 22
  • 23. 2nt October 2011 Design Pattern : Abstract 23