# Singleton Pattern

> A design pattern that restricts a class to one instance, reached through a global access point.

Record: `architecture:singleton-pattern`
Kind: pattern
Layer: [Design Patterns Core](https://banes-lab.com/records/layer/design-patterns-core.md)
Severity: discouraged
Scope: object_creation, lifetime, composition root
Canonical: https://banes-lab.com/ontology#architecture-singleton-pattern

Listed in [Architecture principles](https://banes-lab.com/api/records/architecture.md), after [Prototype Pattern](https://banes-lab.com/records/architecture/prototype-pattern.md) and before [Adapter Pattern](https://banes-lab.com/records/architecture/adapter-pattern.md).

## Repair

- Refactored by: Compose Single Instance at the Root, Inject It
- Detected by: static global access to a shared service
- Violated by: a global mutable instance reached from anywhere
- Measured by: global-instance reach-in count
- Enforced by: composition-root review

## Requires

- [Single-Instance Need](https://banes-lab.com/records/lexicon/single-instance-need.md)

## Reinforces

- [Controlled Instantiation](https://banes-lab.com/records/lexicon/controlled-instantiation.md)

## Enables

- [Shared Resource Access](https://banes-lab.com/records/lexicon/shared-resource-access.md)

## Conflicts with

- [Global Mutable State](https://banes-lab.com/records/lexicon/global-mutable-state.md)

## In tension with

- [Testability](https://banes-lab.com/records/architecture/testability.md)
- [Dependency Injection](https://banes-lab.com/records/architecture/dependency-injection.md)

## Tensions

- [Singleton Pattern / Testability](https://banes-lab.com/records/tension/singleton-pattern-testability.md)
- [Singleton Pattern / Dependency Injection](https://banes-lab.com/records/tension/dependency-injection-singleton-pattern.md)

## Severity

- [discouraged](https://banes-lab.com/records/vocabulary/severity-discouraged.md)

## Category

- [Creational Patterns](https://banes-lab.com/records/architecture-category/creational-patterns.md)

## Force

- [Object creation](https://banes-lab.com/records/force/object-creation.md)

## Linked from

- [Correctness / Determinism / Verification](https://banes-lab.com/ontology/principles/architecture-category-correctness-determinism-verification.md)
- [Plugin / Extensibility / IoC](https://banes-lab.com/ontology/principles/architecture-category-plugin-extensibility-ioc.md)
- [Creational Patterns](https://banes-lab.com/ontology/lexicon/lexicon-category-creational-patterns.md)
- [Severity levels](https://banes-lab.com/ontology/schema/the-vocabulary-severity.md)
- [The forces](https://banes-lab.com/ontology/schema/the-forces.md)
- [The resolutions](https://banes-lab.com/ontology/schema/the-resolutions.md)
