← CS Visual Lab · Design Patterns
1️⃣ Singleton
💡 The ideaOnly one object of a class exists, with one global access point. Used for a config, a logger or a database pool.
🏠 In real lifeA college has one principal. Everyone who asks "who is the principal?" gets the same person.
🎬 Watch it work
Step 1 of 4
Private constructor
Nobody outside the class can call new, so no one can make a second object.
class Config {
private static instance: Config | null = null;
private constructor() {}
}