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

[デザインパターン勉強会]FactoryMethodパターン

Avatar for mei28 mei28
August 11, 2020
36

 [デザインパターン勉強会]FactoryMethodパターン

Seeeeee:Dの夏休み勉強会での資料.

Avatar for mei28

mei28

August 11, 2020
Tweet

More Decks by mei28

Transcript

  1.  ॳ৺ऀ͕ௐཧ͍ͯ͘͠Α /PU'BDUPSZ.FUIPE ͱΓ͋͑ͣ$PPLQBEΛݟΔ͔ class Shoshinsya_Chouri(metaclass=ABCMeta): @abstractmethod def kiru(self): raise

    NotImplemented @abstractmethod def yaku(self): raise NotImplemented @abstractmethod def nikomu(self): raise NotImplemented def chouri(self): cookpad = Cookpad(self.shokuzai) self.kiru(cookpad.recipe) self.yaku(cookpad.recipe) self.nikomu(cookpad.recipe) print("Ͱ͖ͨʂ") class Shoshinsya(Shoshinsya_Chouri): def __init__(self, shokuzai): self.shokuzai = shokuzai def kiru(self, cookpad): print(f'{cookpad}Λࢀߟʹͯ͠{self.shokuzai}Λ੾Δͧ') def yaku(self, cookpad): print(f'{cookpad}Λࢀߟʹͯ͠{self.shokuzai}Λম͍͍ͯ͘') def nikomu(self, cookpad): print(f'{cookpad}Λࢀߟʹͯ͠{self.shokuzai}ΛࣽࠐΉΑ') ਌ΦϒδΣΫτͰ ϨγϐΛࢦఆͯ͠ ݟ͍ͯΔϨγϐ
  2.  ͍ΖΜͳϨγϐʹରԠ͠Α͏ 'BDUPSZ.FUIPE αϒΫϥεͰϨγϐΛੜ੒͍ͯ͘͠Α class Chukyusha_Chouri(metaclass=ABCMeta): #snip def chouri(self): recipe

    = self.nanidetsukuru() self.kiru(recipe.recipe) self.yaku(recipe.recipe) self.nikomu(recipe.recipe) print("Ͱ͖ͨʂ") @abstractmethod def nanidetsukuru(self): raise NotImplementedError class Chukyusha(Chukyusha_Chouri): #snip def nanidetsukuru(self): return Kurashiru(self.shokuzai) αϒΫϥεʹ ·͔ͤΔ ਌Ϋϥεʹ೚͞Ε ͨϨγϐΛܾΊΔ