← Back to libraryQuestion 19 of 273
JavaIntermediate

Design Patterns - Singleton

📖 Detailed Explanation:

The Singleton pattern ensures that a class has only ONE instance throughout the application lifetime and provides a global point of access to it. Use cases: Database connection pool, Logger, Configuration manager. Modern Java: Enum Singleton is the best approach.

🌍 Real-World Example:

A Database Connection Pool. You don't want every part of your app creating its own connection pool; you want one central pool that everyone shares and reuses.

🎯 Scenario-Based Interview Question:

How do you make a Singleton class thread-safe without sacrificing performance? Compare different approaches.