As the title says, is it a good practice to have multiple template methods?
Here is an example to demonstrate the situation:
class BaseTemplate:
def template1(self):
self.primitive1()
self.primitive3()
def template2(self):
self.primitive3()
self.primitive2()
class Concrete1(BaseTemplate):
def primitive1(self):
print("primitive1 called from C1")
def primitive2(self):
print("primitive2 called from C1")
def primitive3(self):
print("primitive3 called from C1")
class Concrete2(BaseTemplate):
def primitive1(self):
print("primitive1 called from C2")
def primitive2(self):
print("primitive2 called from C2")
def primitive3(self):
print("primitive3 called from C2")
Questions:
- If this is not a good pattern then, what are the drawbacks?
- Are there any other solutions for this situation?
Aucun commentaire:
Enregistrer un commentaire