Cognitive Scaffold

Preparing your thinking workspace

arrow_back_ios_new
MENTAL MODEL · M0317

Decorator Pattern

Decorator Pattern
CreateHigh supportDesign Thinking
Included
account_tree

Updated 2026-07-30

Loading revision record…

Summary

In object-oriented programming, the decorator pattern is a design pattern that allows behavior to be added to an individual object dynamically, without affecting the behavior of other instances of the same class. The decorator pattern is often useful for adhering to the Single Responsibility Principle.

Definition

Dynamically add extra responsibilities or functions to an object without changing its original structure. It's like adding a filter to a photo; the photo itself remains unchanged. Scaffold use: painless upgrade. Don't try to change a person's essence (core code). Instead, endow them with new abilities through 'decoration'. For example, equip an introverted employee (core) with a detailed communication SOP (decorator) so they can handle external communication without being forced to become extroverted.

How to use

Painless upgrade. Don't try to change a person's essence (core code). Instead, endow them with new abilities through 'decoration'. For example, equip an introverted employee (core) with a detailed communication SOP (decorator) so they can handle external communication without being forced to become extroverted.

Mechanism

Decorator is a GoF structural pattern that dynamically adds responsibilities to an object without changing its class, offering more flexibility than inheritance.

Practice

In progress 0/3

Practice this model in one real situation:

Check to track your progress (stored locally)
Learning progress0%

Cases

  • Java I/O streams use buffering and encryption decorators to wrap layers.

Common pitfalls

  • Excessive layering can lead to debugging difficulties and type confusion.
Sources

Source support: Explicit

References currently contain only Wikipedia links; primary sources still need review.

  • link
    en.wikipedia.orghttps://en.wikipedia.org/wiki/Decorator_patternZH · Explicit
    verified
account_treeGenealogyexpand_more

RELATED MODELS