This is how I gathered a decorator pattern would work in Python after looking at this answer. Can you help me understand if it's not what the Decorator pattern is all about?
Here, a pizza is ordered with toppings. Adding toppings (the decoration)is done using functions used in chain. The price is updated as the decoration is done and finally a Pizza object with the final price is returned, which is then ordered.
def api_send_order(pizza):
print('Ordered pizza for '+str(pizza.price)+' with toppings of '+str(pizza.toppings))
return True
# designed:
class Pizza():
def __init__(self):
self.price = 100
self.toppings = list()
def order(self):
return api_send_order(self)
def mushroom_topped(pizza):
pizza.price += 20
pizza.toppings.append('mushroom')
return pizza
def extracheese_topped(pizza):
pizza.price += 10
pizza.toppings.append('extra-cheese')
return pizza
# used as:
mushroom_topped(extracheese_topped(Pizza())).order()