Sync Decorator to Java 25: H6 file labels, fix Main.java JDK-output mismatch, README mapping

This commit is contained in:
2026-06-24 14:39:15 +05:30
parent ad6a65a95d
commit d6df1fd013
9 changed files with 79 additions and 60 deletions

View 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/