import abc
class Pizza(metaclass=abc.ABCMeta):
name = ''
toppings = []
def prepare(self):
for i in self.toppings:
print(i, end="")
def bake(self):
print("Bake for 25 minutes at 360")
def cut(self):
print("cutting the pizza into diagonal slices")
def box(self):
print("Place pizza in official PizzaStore box")
def getName(self):
return self.name
class CheesePizza(Pizza):
def __init__(self):
self.name = "Cheese Pizza"
self.toppings.append("Grated Reggiano Cheese")
class PizzaStore(metaclass=abc.ABCMeta):
def orderPizza(self, type):
pizza = self._createPizza(type)
pizza.prepare()
pizza.bake()
pizza.cut()
pizza.box()
return pizza
@abc.abstractmethod
def _createPizza(self, type):
raise NotImplementedError
class CheesePizzaStore(PizzaStore):
def _createPizza(self, type):
if type == "cheese":
return CheesePizza()
else:
return None
if __name__ == '__main__':
pizzaStore = CheesePizzaStore()
pizza = pizzaStore.orderPizza("cheese")
print("You ordered a", pizza.getName())