Last active
May 19, 2022 11:06
-
-
Save takahashilabo/28125871c0ef45832debf595bbf350f7 to your computer and use it in GitHub Desktop.
Mario and Kuribo on Template Method Pattern
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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