archetypos

Where software design patterns meet their Platonic origins

Explore Patterns
Creational Pattern

Singleton

from Greek monos (μόνος) -- one, alone

Ensures a class has only one instance and provides a global point of access to it. Like Plato's Form of the Good -- there is only one, and everything references it.

class Singleton {
  static #instance;
  static getInstance() {
    if (!Singleton.#instance) {
      Singleton.#instance = new Singleton();
    }
    return Singleton.#instance;
  }
}
Stable GoF
Behavioral Pattern

Observer

from Greek theoros (θεωρός) -- spectator, one who observes

Defines a one-to-many dependency between objects so that when one object changes state, all its dependents are notified. Like disciples gathered around a philosopher -- when wisdom speaks, all listen.

class Subject {
  #observers = [];
  subscribe(obs) {
    this.#observers.push(obs);
  }
  notify(data) {
    this.#observers.forEach(
      o => o.update(data)
    );
  }
}
Stable GoF
Creational Pattern

Factory

from Greek demiourgos (δημιουργός) -- craftsman, creator

Defines an interface for creating objects, but lets subclasses decide which class to instantiate. Like the Demiurge of Plato's Timaeus -- the divine craftsman who creates forms from archetypes.

class ShapeFactory {
  create(type) {
    switch(type) {
      case 'circle':
        return new Circle();
      case 'square':
        return new Square();
    }
  }
}
Stable GoF

Pattern Index

The canonical catalog of software archetypes

Adapter

Converts the interface of a class into another interface clients expect.

Structural

Strategy

Defines a family of algorithms, encapsulating each one to be interchangeable.

Behavioral

Decorator

Attaches additional responsibilities to an object dynamically.

Structural

Command

Encapsulates a request as an object, allowing parameterization of clients.

Behavioral

Composite

Composes objects into tree structures to represent part-whole hierarchies.

Structural

Prototype

Creates new objects by copying an existing object -- the prototype.

Creational Deprecated

Dependency Graph

How patterns relate to one another in the archetypal hierarchy

Singleton Factory Observer Strategy Adapter Decorator Command Composite Prototype