QamoosTech
Architecture & DesignPatternsIntermediatePython

Registry Pattern

PronunciationREJ-is-tree PAT-ern

Definition

The registry pattern collects functions or classes into a lookup, usually a dictionary, so code can find the right one by name instead of using a long chain of if statements.

Where you hear it

In plugin systems, CLI command handlers, serializers, and Python code with a @register decorator.

Examples

  • Each command registers itself, and the CLI looks it up by name.
  • Adding a new exporter means adding one function; no if chain to edit.
  • The registry maps command names to handlers, so the CLI looks each one up by name.

Common mistake

Letting the registry become a hidden global that tests and imports change. Keep registration explicit and test it.

Don't confuse with

Dependency injection, where you pass the needed object in. A registry is a shared lookup the code reaches into.

Say it at work

  • In a meeting or chatUse a registry so new handlers plug in without editing the core.
  • In an email or ticketRegister the function with the decorator.