A conceptual blueprint (it is an idea)
- A proven, reusable solution to a recurring software design problem, at the design level, not code level.
- Not a library / framework / specific code
- ✅ Loose coupling
- ✅ Open/Closed Principle
- ✅ Scalability
- ✅ Maintainability
- ✅ Testability
CREATIONAL PATTERNS (Object creation)
1. Singleton
- Private constructor
- Cannot create extra instance
- Static final instance
- Global access point
- thread safe
- JVM guarantees initialization once
- Public access method
- Real-world usage:
- Spring beans (by default)
- Logger
- Cache manager
public class ConfigManager {
private static final ConfigManager INSTANCE = new ConfigManager();
private ConfigManager() {}
public static ConfigManager getInstance() {
return INSTANCE;
}
}
Singleton ≠ global variable
Singleton controls creation + lifecycle