Skip to content

Instantly share code, notes, and snippets.

@takahashilabo
Last active May 19, 2022 11:06
Show Gist options
  • Save takahashilabo/28125871c0ef45832debf595bbf350f7 to your computer and use it in GitHub Desktop.
Save takahashilabo/28125871c0ef45832debf595bbf350f7 to your computer and use it in GitHub Desktop.
Mario and Kuribo on Template Method Pattern
class Chara:
def __init__(self):
self.__cs = []
def add(self, c):
self.__cs.append(c)
def draw(self) :
pass
def drawAll(self):
for c in self.__cs:
c.draw()
class Mario(Chara):
def draw(self):
print("マリオ")
class Kuribo(Chara):
def draw(self):
print("クリボ")
chara = Chara()
chara.add(Mario())
chara.add(Kuribo())
chara.drawAll()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment