Sync Decorator to Java 25: H6 file labels, fix Main.java JDK-output mismatch, README mapping
This commit is contained in:
32
02-structural/decorator/README.md
Normal file
32
02-structural/decorator/README.md
Normal file
@@ -0,0 +1,32 @@
|
||||
# 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/
|
||||
Reference in New Issue
Block a user