Decorator pattern

/ˈdɛkəreɪtər ˈpætərn/ noun

Definition

A design pattern that allows behavior to be added to objects dynamically without altering their structure by wrapping them in decorator objects. Each decorator implements the same interface as the original object and can add functionality before or after delegating to the wrapped object.

Etymology

Named after the concept of decorating (adding ornaments to) something without changing its core structure, formalized in the Gang of Four book (1994). The pattern provides an alternative to subclassing for extending functionality, avoiding the 'explosion of subclasses' problem.

Kelly Says

The Decorator pattern is like customizing a coffee order - you start with basic coffee and wrap it with decorators like 'extra shot', 'whipped cream', and 'caramel syrup', each adding its own behavior without changing the original coffee! This is how middleware works in web frameworks, where each layer adds functionality like authentication or logging.

Related Words

Explore More Words

Get the Word Orb API

Complete word intelligence in one call. Free tier — 50 lookups/day.