Sync Singleton to Java 25: split 6 implementations into separate files, consolidated Main.java demo
This commit is contained in:
20
README.md
20
README.md
@@ -158,6 +158,26 @@ javac 01-creational/prototype/*.java -d out/prototype
|
||||
java -cp out/prototype prototype.Main
|
||||
```
|
||||
|
||||
### Singleton (`01-creational/singleton/`)
|
||||
|
||||
| Post Section | File(s) |
|
||||
|---|---|
|
||||
| Implementation 1 — Eager Initialization | `AppConfigEager.java` |
|
||||
| Implementation 2 — Naïve Lazy Initialization | `AppConfigNaiveLazy.java` |
|
||||
| Implementation 3 — Synchronized Method | `AppConfigSynchronized.java` |
|
||||
| Implementation 4 — Double-Checked Locking | `AppConfigDCL.java` |
|
||||
| Implementation 5 — Initialization-on-Demand Holder | `AppConfigHolder.java` |
|
||||
| Implementation 6 — Enum Singleton | `AppConfigEnum.java` |
|
||||
| Running All Six Implementations Together | `Main.java` |
|
||||
|
||||
Each implementation is renamed to its own class (e.g. `AppConfigEager`, `AppConfigHolder`) so all six can be compiled together in one package and compared directly. `Main.java` exercises all six in one run. The "Breaking via Reflection," "Breaking via Serialization," and Spring `@Component` snippets are illustrative only — they are not part of this repository's runnable example.
|
||||
|
||||
Run it:
|
||||
```bash
|
||||
javac 01-creational/singleton/*.java -d out/singleton
|
||||
java -cp out/singleton singleton.Main
|
||||
```
|
||||
|
||||
## Reference
|
||||
|
||||
- *Design Patterns: Elements of Reusable Object-Oriented Software* — Gamma, Helm, Johnson, Vlissides
|
||||
|
||||
Reference in New Issue
Block a user