Created
September 2, 2018 10:25
-
-
Save santosh/8898ba78b24b6f822283aee49f51712d to your computer and use it in GitHub Desktop.
Template Method Pattern example in Python.
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
from abc import ABC, abstractmethod | |
class AbstractRecipe(ABC): | |
def execute(self): | |
self.prepare() | |
self.recipe() | |
self.cleanup() | |
@abstractmethod | |
def prepare(self): | |
pass | |
@abstractmethod | |
def recipe(self): | |
pass | |
@abstractmethod | |
def cleanup(self): | |
pass | |
class Recipe1(AbstractRecipe): | |
def prepare(self): | |
print("do the dishes") | |
print("get raw materials") | |
def recipe(self): | |
print("execute the steps") | |
def cleanup(self): | |
pass | |
recipe1 = Recipe1() | |
recipe1.execute() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment