Sync Composite to Java 25: H6 file labels, fix console output typo, README mapping
This commit is contained in:
30
02-structural/composite/README.md
Normal file
30
02-structural/composite/README.md
Normal file
@@ -0,0 +1,30 @@
|
||||
# Composite Design Pattern — Java Example
|
||||
|
||||
**Pattern:** Structural → Composite
|
||||
**Article:** https://ankurm.com/composite-design-pattern-java/
|
||||
|
||||
## What this example shows
|
||||
|
||||
Builds a file system tree where files (leaves) and directories (composites) share the same `FileSystemItem` interface. Callers compute size or print the tree without ever checking whether a node is a file or a directory.
|
||||
|
||||
## How to run
|
||||
|
||||
```bash
|
||||
javac composite/*.java -d out/composite
|
||||
java -cp out/composite composite.Main
|
||||
```
|
||||
|
||||
Requires Java 25.
|
||||
|
||||
## Post Section ↔ File Mapping
|
||||
|
||||
| Post Section | File(s) |
|
||||
|---|---|
|
||||
| The Problem: Treating Leaves and Containers Uniformly | illustrative only — not part of this repository's runnable example |
|
||||
| Step 1 — The Component Interface | `FileSystemItem.java` |
|
||||
| Step 2 — The Leaf (File) | `File.java` |
|
||||
| Step 3 — The Composite (Directory) | `Directory.java` |
|
||||
| Building and Using the Tree | `Main.java` |
|
||||
|
||||
Article: https://ankurm.com/composite-design-pattern-java/
|
||||
All patterns: https://ankurm.com/design-patterns-java/
|
||||
Reference in New Issue
Block a user