Add per-pattern README.md for the 5 creational patterns (Factory Method, Abstract Factory, Builder, Prototype, Singleton) for consistency with all other 18 patterns
This commit is contained in:
30
01-creational/builder/README.md
Normal file
30
01-creational/builder/README.md
Normal file
@@ -0,0 +1,30 @@
|
||||
# Builder Design Pattern — Java Example
|
||||
|
||||
**Pattern:** Creational → Builder
|
||||
**Article:** https://ankurm.com/builder-design-pattern-java/
|
||||
|
||||
## What this example shows
|
||||
|
||||
An immutable `HttpRequest` assembled step by step instead of through a constructor with a dozen optional parameters. `HttpRequest` is the product — built once, never mutated afterward. `HttpClientConfig` is a director-style helper that encapsulates common request configurations so callers don't repeat the same builder calls. `Main` wires it together and shows the fluent builder chain in action.
|
||||
|
||||
## How to run
|
||||
|
||||
```bash
|
||||
javac builder/*.java -d out/builder
|
||||
java -cp out/builder builder.Main
|
||||
```
|
||||
|
||||
Requires Java 25.
|
||||
|
||||
## Post Section ↔ File Mapping
|
||||
|
||||
| Post Section | File(s) |
|
||||
|---|---|
|
||||
| Part 1 — The Product: HttpRequest (Immutable) | `HttpRequest.java` |
|
||||
| Part 2 — The Director: Encapsulating Common Configurations | `HttpClientConfig.java` |
|
||||
| Part 3 — Using the Builder: Client Code | `Main.java` |
|
||||
|
||||
Note: the Lombok `@Builder` example and the JDK standard-library snippets (`HttpRequest.newBuilder()`, `StringBuilder`, `ProcessBuilder`) are illustrative only — they are not part of this repository's runnable example.
|
||||
|
||||
Article: https://ankurm.com/builder-design-pattern-java/
|
||||
All patterns: https://ankurm.com/design-patterns-java/
|
||||
Reference in New Issue
Block a user