Mid GoF Patterns

Decorator (CoffeeDecorator):?

  • The CoffeeDecorator class is an abstract class that implements the

ICoffee interface and holds a reference to an ICoffee object. This class

allows us to add additional behavior to the coffee object, but we don't modify

the base class (SimpleCoffee).

public abstract class CoffeeDecorator : ICoffee

protected ICoffee _coffee;

protected CoffeeDecorator(ICoffee coffee) => _coffee = coffee;

public virtual double Cost() => _coffee.Cost();

public virtual string Description() => _coffee.Description();

More from Design Patterns in C#

All questions for this course