template method 패턴

김대익·2022년 3월 31일
0

클래스의 메서드들이 template으로 제공되는 패턴

class BasicRamenRecipe:
  def cookRamen(self):
    self.boilWater()
    self.addRamen()
    self.addons()
    self.wait()

  def boilWater(self):
    print("boil 550ml of water")
  def addRamen(self):
    print("add noodles, soup Base, flakes")
  def addons(self):
    pass
  def wait(self):
    print("cook for 4min 30s")
    
class NocopeRecipe(BasicRamenRecipe):
  def addons(self):
    print("add onions")

class GrandmaRecipe(BasicRamenRecipe):
  def boilWater(self):
    print("boil 1000ml of water")
  def wait(self):
    print("cook for 10m")

0개의 댓글