⌘K
Flycodx

Decorator Pattern: Coffee Shop and Text Editor

Decorator Pattern: Coffee Shop and Text Editor

MediumLLD0% accepted

Implement the Decorator design pattern. Use case: coffee shop where beverage is decorated with condiments (milk, sugar, whip) dynamically. Each condiment wraps the beverage and adds its cost and description.

Approach

Implement Decorator pattern for dynamic feature addition without subclassing.

Input

Espresso with double milk and whip

Output

new Whip(new Milk(new Milk(new Espresso()))); cost = espresso + 2*milk + whip; description concatenated

Scenarios & Expected Answers

Sign in to continue

Create a free account to view answers and mark progress.

  • Free forever — no credit card
  • Theory Q&A with detailed answers
  • Points, streaks & leaderboards
Auto Save On