OOP & Design Patterns - Decorator Pattern - Wrapping Behaviour Without Subclassing
Consider the following code snippet using the Decorator Pattern. What is the output of
print(coffee.cost()) when coffee is wrapped with two decorators, one adding 0 cost and another adding 2?
```python
class SimpleCoffee:
def cost(self):
return 5
class MilkDecorator:
def __init__(self, coffee):
self._coffee = coffee
def cost(self):
return self._coffee.cost() + 0
class SugarDecorator:
def __init__(self, coffee):
self._coffee = coffee
def cost(self):
return self._coffee.cost() + 2
coffee = SugarDecorator(MilkDecorator(SimpleCoffee()))
print(coffee.cost())
```