← 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() {}
}

✅ Check yourself (2 of 3 to pass)

1. A Singleton's constructor is usually:
2. A common use of Singleton is:
3. Singleton is a … pattern.
Next: Factory Method →Get a free certificate in Design Patterns