Skip to main content
PreparationZone Logo
PrepZone

Decorator Pattern

Add responsibilities dynamically without subclass explosion.

Pass checkpoint below

Read these first

Why this matters

  • Wrapper chain — detailed pointwise breakdown in the section below.
  • Coffee shop example — detailed pointwise breakdown in the section below.
  • I/O decorators — detailed pointwise breakdown in the section below.
  • vs inheritance — detailed pointwise breakdown in the section below.
  • Patterns are forces and solutions — name the force before the pattern.
Wrapped component
LoggingDecorator
RetryDecorator
CoreService
Wrap behaviour in layers without subclass explosion.

Overview

Add responsibilities dynamically without subclass explosion. Study each section below in order — every list is interview-ready reference material.

Wrapper chain

Points to cover

  • Definition — what Wrapper chain means in one clear sentence
  • When to use — the force or smell that triggers this concept
  • CampusOS example — where this appears in parking, booking, or library modules
  • How to explain — pointwise bullets you can say aloud in an interview
  • Common mistake — what weak candidates do instead
  • Refactor move — one concrete change that improves the design

The rest of this guide is part of Pro

Free covers every fresher guide in full. Pro unlocks Senior, Staff and Architect guides across every track.

Still to come · 3 sections

  • Coffee shop example
  • I/O decorators
  • vs inheritance

Test yourself

Answer these before moving on — recall is what makes it stick.