# Decorator Design Pattern — Java Example **Pattern:** Structural → Decorator **Article:** https://ankurm.com/decorator-design-pattern-java/ ## What this example shows Builds a text-processing pipeline where behaviours (trim, uppercase, profanity filter) are stacked as wrapper objects around a `PlainTextProcessor`, all sharing the `TextProcessor` interface — the same idea behind `new BufferedReader(new InputStreamReader(...))` in the JDK. ## How to run ```bash javac decorator/*.java -d out/decorator java -cp out/decorator decorator.Main ``` Requires Java 25. ## Post Section ↔ File Mapping | Post Section | File(s) | |---|---| | Step 1 — Component Interface | `TextProcessor.java` | | Step 2 — Concrete Component | `PlainTextProcessor.java` | | Step 3 — Base Decorator | `TextDecorator.java` | | Step 4 — Concrete Decorators | `UpperCaseDecorator.java`, `TrimDecorator.java`, `ProfanityFilterDecorator.java` | | Stacking the Decorators — Order Matters | `Main.java` | Note: the JDK `InputStream`/`BufferedInputStream`/`GZIPInputStream` snippet under "Decorator in the JDK: I/O Streams" is illustrative only — it is not part of this repository's runnable example. Article: https://ankurm.com/decorator-design-pattern-java/ All patterns: https://ankurm.com/design-patterns-java/