Singleton-Pattern (EN)

Concept

A pattern that ensures a class has only one instance and provides a global access point

Architecture

flowchart TD     A[Client 1] --> B[Singleton Instance]     A --> C[Singleton Access Method]     D[Client 2] --> B     D --> C     E[Client 3] --> B     E --> C     classDef client fill:#f9f,stroke:#333,stroke-width:2px;     classDef singleton fill:#bbf,stroke:#333,stroke-width:2px;     classDef method fill:#bfb,stroke:#333,stroke-width:2px;     class A,D,E client;     class B singleton;     class C method; 

In Context

  • Typically used together with Factory Pattern or Dependency Injection
  • Related to: Factory Pattern, Dependency Injection, Global State
  • Example use cases: Database connections, Logging systems, Configuration managers
Quelle: AI Generated