Skip to content

Instantly share code, notes, and snippets.

@santosh
Created September 2, 2018 10:25
Show Gist options
  • Save santosh/8898ba78b24b6f822283aee49f51712d to your computer and use it in GitHub Desktop.
Save santosh/8898ba78b24b6f822283aee49f51712d to your computer and use it in GitHub Desktop.
Template Method Pattern example in Python.
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