Upgrade to Pro — share decks privately, control downloads, hide ads and more …

デザインパターン入門とオブジェクト指向について

Sponsored · Ship Features Fearlessly Turn features on and off without deploys. Used by thousands of Ruby developers.

 デザインパターン入門とオブジェクト指向について

デザインパターン入門とオブジェクト指向について

Avatar for よしたろう

よしたろう

August 16, 2022
Tweet

More Decks by よしたろう

Other Decks in Programming

Transcript

  1. Template Method Pattern ڞ௨ͳॲཧʢॲཧॱংʣ ৔߹ͰҟͳΔ۩ମతͳॲཧ಺༰ ෼཭ͨ͠σβΠϯύλʔϯ public abstract class AbstractDisplay

    { //αϒΫϥεʹ࣮૷Λ·͔ͤΔந৅ϝιου public abstract void displayHeader(); public abstract void displayBody(); public abstract void displayFooter(); // AbstractDisplayͰ࣮૷ͯ͠Δϝιου public final void display() { displayHeader(); for (int i = 0; i < 5; i++) { displayBody(); } displayFooter(); } }
  2. • Abstract Pattern (AbstractClass ) • Template Method Pattern (

    Abstract ) • Factory Method Pattern ( TemplateMethod ) • Dependency Injection Pattern ( FactoryMethod ) ύλʔϯͷதʹผͷύλʔϯ͕ଘࡏ͢Δ
  3. 変更  Core:最 使⽤ 重要  Creational:⽣成 関  Peripheral: 使  Other: 他

    変更(1):Factory Method Factory ⼀般化 新規追加(4):Null Object, Type Object, Dependency Injection, Extension Object/Interface 削除(6):Singleton, Adapter, Bridge, Chain of Responsibility, Memento, Observer 格下 :Flyweight, Interpreter BBBBBBB BBBBBBB BBBBBBB BBBBBBB BBBBBB
  4. ॲ ཧ ͷ ྲྀ Ε ෆมͳॲཧ ՄมͳॲཧΛநग़ ͯ͠ந৅Խ͢Δ (interface /

    abstract) ෆมͳॲཧ 可変を外部に 抽出!!
  5. ॲ ཧ ͷ ྲྀ Ε ෆมͳॲཧ ՄมͳॲཧΛநग़ ͯ͠ந৅Խ͢Δ (interface /

    abstract) ෆมͳॲཧ ந৅Խॲཧ ͷ۩৅Խ (implements / extends) ந৅Խॲཧ ͷ۩৅Խ (implements / extends) ந৅Խॲཧ ͷ۩৅Խ (implements / extends)
  6. ՄมͳॲཧΛநग़ ͯ͠ந৅Խ͢Δ (interface / abstract) ந৅Խॲཧ ͷ۩৅Խ (implements / extends)

    ந৅Խॲཧ ͷ۩৅Խ (implements / extends) ந৅Խॲཧ ͷ۩৅Խ (implements / extends) ॲ ཧ ͷ ྲྀ Ε ෆมͳॲཧ ෆมͳॲཧ 可変が消えて 不変が残り 安定化!! 単体で⾒れば 具象クラス達は 安定している!
  7. ՄมͳॲཧΛநग़ ͯ͠ந৅Խ͢Δ (interface / abstract) 新しい処理は 
 クラス追加 で実現する ந৅Խॲཧ

    ͷ۩৅Խ (implements / extends) ந৅Խॲཧ ͷ۩৅Խ (implements / extends) ந৅Խॲཧ ͷ۩৅Խ (implements / extends) ந৅Խॲཧ ͷ۩৅Խ (implements / extends) ॲ ཧ ͷ ྲྀ Ε ෆมͳॲཧ ෆมͳॲཧ
  8. ՄมͳॲཧΛநग़ ͯ͠ந৅Խ͢Δ (interface / abstract) ந৅Խॲཧ ͷ۩৅Խ (implements / extends)

    ந৅Խॲཧ ͷ۩৅Խ (implements / extends) ந৅Խॲཧ ͷ۩৅Խ (implements / extends) ந৅Խॲཧ ͷ۩৅Խ (implements / extends) ॲ ཧ ͷ ྲྀ Ε ෆมͳॲཧ ෆมͳॲཧ
  9. ・継承 委譲( ) ・具象 (抽象) ・「変更 部分」 「変更 部分」 分離

    ・ 指向 本質的 再利⽤性 提⽰ σβΠϯύλʔϯ͕ڭ͑ͯ͘Εͨ͜ͱ
  10. ॲ ཧ ͷ ྲྀ Ε ෆมͳॲཧ ՄมͳॲཧΛநग़ ͯ͠ந৅Խ͢Δ (interface /

    abstract) ෆมͳॲཧ ෆมͳॲཧ ந৅Խॲཧ ͷ۩৅Խ (implements / extends) ந৅Խॲཧ ͷ۩৅Խ (implements / extends) ந৅Խॲཧ ͷ۩৅Խ (implements / extends) ந৅Խॲཧ ͷ۩৅Խ (implements / extends) 可変な処理が 不変な処理に!
  11. ・ 指向 ⽬標 「変更容易性」 ・ 変更 強 構造 ・ 使

    注意 必要 ・現代 ⽅向性 ・継承 委譲 ・具象 (抽象) ・ 指向 本質的 再利⽤性 提⽰ ・「変更 部分」 「変更 部分」 分離 σβΠϯύλʔϯ͕ڭ͑ͯ͘Εͨ͜ͱ