How does the Decorator pattern promote flexibility in extending object behavior?

The Decorator pattern extends an object's behavior at runtime by wrapping it in one or more decorator objects that implement the same interface as the original. This gives flexible, composable behavior without relying on subclassing.

Key Points: • Decorators implement the same interface as the wrapped object, so they're transparent to the client. • Multiple decorators can be stacked to combine behaviors in different orders and combinations. • Behavior is added per-instance at runtime rather than fixed at compile time through inheritance. • It avoids a combinatorial explosion of subclasses for every possible feature combination. • The original class remains untouched, respecting the open/closed principle.

Example: A text editor might wrap a plain TextView with a SpellCheckDecorator and a HighlightDecorator, letting you enable or disable each feature per instance simply by choosing which decorators to apply, instead of creating a subclass for every combination.

Interview Tip: A concise interview answer is:

"Decorator promotes flexibility by letting you wrap an object with additional behavior at runtime, and because decorators share the same interface as the original object, you can stack several of them in any combination without creating a new subclass for every feature combination."