diff --git a/factory-method/README.md b/factory-method/README.md index 4334b052353d..d45a6aa0cac7 100644 --- a/factory-method/README.md +++ b/factory-method/README.md @@ -31,6 +31,9 @@ Real-world example In plain words > It provides a way to delegate the instantiation logic to child classes. +> +> Imagine a messaging app that can send notifications by Email, SMS, or Push Notifications. +> The user only asks to send a message. The Factory Method chooses and creates the correct notification service Wikipedia says diff --git a/singleton/README.md b/singleton/README.md index 92505061399e..48cbc211aa24 100644 --- a/singleton/README.md +++ b/singleton/README.md @@ -37,6 +37,17 @@ Sequence diagram ![Singleton Pattern sequence diagram](./etc/singleton-sequence-diagram.png) +## Singleton Implementation Comparison (for eager and lazy initialization) + +| Feature | Eager Initialization | Thread-Safe Lazy Initialization | +|----------|----------|----------| +| Object Creation | During class loading | First call to `getInstance()` | +| Thread Safe | Yes | Yes | +| Synchronization Required | No | Yes | +| Memory Usage | Higher | Lower | +| Performance | Faster access | Slight synchronization overhead | +| Complexity | Simple | Moderate | + ## Programmatic Example of Singleton Pattern in Java Joshua Bloch, Effective Java 2nd Edition p.18