Skip to content

Singleton

Easy — everyone uses thisArchitecture

ELI5 — The Vibe Check

Singleton is a pattern that ensures only ONE instance of a class exists in your entire app. It's like the CEO — there's only one, everyone talks to the same person, and creating a second CEO would cause chaos. Database connections and config objects are often singletons.

Real Talk

The Singleton pattern is a creational design pattern that restricts instantiation of a class to a single object and provides a global access point to it. Often criticized for introducing global state, making testing harder and creating hidden dependencies.

Show Me The Code

class Config {
  private static instance: Config;
  private constructor() {}

  static getInstance(): Config {
    if (!Config.instance) {
      Config.instance = new Config();
    }
    return Config.instance;
  }
}

When You'll Hear This

"The logger is a Singleton — same instance everywhere." / "Singletons are controversial because they make unit testing harder."

Made with passive-aggressive love by manoga.digital. Powered by Claude.