# Creational Patterns

> Every principle in this category is listed as a record.

Page: Ontology · Principles
Canonical: https://banes-lab.com/ontology#architecture-category-creational-patterns

Listed in [Ontology · Principles](https://banes-lab.com/api/pages/ontology/principles.md), after [Behavioral Patterns](https://banes-lab.com/ontology/principles/architecture-category-behavioral-patterns.md) and before [Structural Patterns](https://banes-lab.com/ontology/principles/architecture-category-structural-patterns.md).

Every principle in this category is listed as a record. Each record carries its kind, its severity, the scopes it applies at and the layer it lives in, then the edge relations that join it to other records, the records that point back at it, the contracts that answer to it and the tensions it takes part in. The descriptors say how it is violated, detected, measured, repaired and enforced. Where the record carries one, an exemplar shows the shape before and after the principle is applied.

Relations diagram

The relations inside this category.

```mermaid
flowchart LR
n_factory_pattern["Factory Pattern"]
n_factory_method_pattern["Factory Method Pattern"]
n_abstract_factory_pattern["Abstract Factory Pattern"]
n_builder_pattern["Builder Pattern"]
n_prototype_pattern["Prototype Pattern"]
n_singleton_pattern["Singleton Pattern"]
```

### Factory Pattern

- Kind: [pattern](https://banes-lab.com/records/kind/pattern.md)
- Category: [Creational Patterns](https://banes-lab.com/ontology/principles/architecture-category-creational-patterns.md)
- Severity: [recommended](https://banes-lab.com/records/vocabulary/severity-recommended.md)
- Scope: [object_creation](https://banes-lab.com/records/force/object-creation.md), module
- Layer: [Design Patterns Core](https://banes-lab.com/records/layer/design-patterns-core.md)

Details

Definition
A design pattern that moves the construction of an object and its defaults into one function or object.

Requires
[Creation Variation](https://banes-lab.com/records/lexicon/creation-variation.md)

Reinforces
[Open/Closed Principle (OCP)](https://banes-lab.com/records/architecture/open-closed.md), [Encapsulation](https://banes-lab.com/records/architecture/encapsulation.md)

Enables
[Polymorphic Construction](https://banes-lab.com/records/lexicon/polymorphic-construction.md)

In tension with
[Simplicity](https://banes-lab.com/records/lexicon/simplicity.md)

Conflicts with
[Scattered Construction Logic](https://banes-lab.com/records/lexicon/scattered-construction-logic.md)

Referenced by
[Registry Pattern](https://banes-lab.com/records/architecture/registry-pattern.md)

Tensions
[Factory Pattern / Simplicity](https://banes-lab.com/records/tension/factory-pattern-simplicity.md)

Violated by
duplicated conditional construction

Detected by
repeated constructors/switches

Measured by
construction duplication count

Refactored by
Extract Factory

Enforced by
creation policy review

Before

```typescript
const foo = new Foo("foo", 0, [], new Date(), "draft");
```

After

```typescript
function makeFoo(name: string): Foo {
return new Foo(fooId(), name, 0, [], clock.now(), "draft");
}
```

How it is checked

Checked by
creation policy review

Population
Every construction site of the types the pattern governs

Freshness
A verdict stands until a constructor, a variant or the composition root changes

Refusal
The review or the construction test rejects a construction that bypasses the creational owner

Observation
Constructor call sites and their argument counts, read from source

Evidence
None, because the catalog states this check as a class, so a watched run belongs to each system that adopts it

Authoritative side
The creational owner, which every construction site goes through

Depends on
[Creation Variation](https://banes-lab.com/records/lexicon/creation-variation.md), [Open/Closed Principle (OCP)](https://banes-lab.com/records/architecture/open-closed.md), [Encapsulation](https://banes-lab.com/records/architecture/encapsulation.md), [Polymorphic Construction](https://banes-lab.com/records/lexicon/polymorphic-construction.md)

Shape it refuses
[Scattered Construction Logic](https://banes-lab.com/records/lexicon/scattered-construction-logic.md)

### Factory Method Pattern

- Kind: [pattern](https://banes-lab.com/records/kind/pattern.md)
- Category: [Creational Patterns](https://banes-lab.com/ontology/principles/architecture-category-creational-patterns.md)
- Severity: [contextual](https://banes-lab.com/records/vocabulary/severity-contextual.md)
- Scope: class hierarchy, framework
- Layer: [Design Patterns Core](https://banes-lab.com/records/layer/design-patterns-core.md)

Details

Definition
A design pattern in which a base class calls an overridable method to create the objects its workflow uses.

Requires
[Subclass-Controlled Creation](https://banes-lab.com/records/lexicon/subclass-controlled-creation.md)

Reinforces
[Open/Closed Principle (OCP)](https://banes-lab.com/records/architecture/open-closed.md)

Enables
[Deferred Instantiation](https://banes-lab.com/records/lexicon/deferred-instantiation.md)

In tension with
[Inheritance Complexity](https://banes-lab.com/records/lexicon/inheritance-complexity.md)

Conflicts with
[Concrete Constructor Coupling](https://banes-lab.com/records/lexicon/concrete-constructor-coupling.md)

Tensions
[Factory Method Pattern / Inheritance Complexity](https://banes-lab.com/records/tension/factory-method-pattern-inheritance-complexity.md)

Violated by
fixed construction in base workflow

Detected by
base class directly instantiates variant

Measured by
variant construction duplication

Refactored by
Introduce Factory Method

Enforced by
[design review](https://banes-lab.com/records/architecture/design-review.md)

Before

```typescript
class FooImporter {
import(raw: string) { return new JsonFooParser().parse(raw); }
}
```

After

```typescript
abstract class FooImporter {
protected abstract parser(): FooParser;
import(raw: string) { return this.parser().parse(raw); }
}
class JsonFooImporter extends FooImporter {
protected parser() { return new JsonFooParser(); }
}
```

How it is checked

Checked by
design review

Population
Every construction site of the types the pattern governs

Freshness
A verdict stands until a constructor, a variant or the composition root changes

Refusal
The review or the construction test rejects a construction that bypasses the creational owner

Observation
Constructor call sites and their argument counts, read from source

Evidence
None, because the catalog states this check as a class, so a watched run belongs to each system that adopts it

Authoritative side
The creational owner, which every construction site goes through

Depends on
[Subclass-Controlled Creation](https://banes-lab.com/records/lexicon/subclass-controlled-creation.md), [Open/Closed Principle (OCP)](https://banes-lab.com/records/architecture/open-closed.md), [Deferred Instantiation](https://banes-lab.com/records/lexicon/deferred-instantiation.md)

Shape it refuses
[Concrete Constructor Coupling](https://banes-lab.com/records/lexicon/concrete-constructor-coupling.md)

### Abstract Factory Pattern

- Kind: [pattern](https://banes-lab.com/records/kind/pattern.md)
- Category: [Creational Patterns](https://banes-lab.com/ontology/principles/architecture-category-creational-patterns.md)
- Severity: [contextual](https://banes-lab.com/records/vocabulary/severity-contextual.md)
- Scope: product family, component
- Layer: [Design Patterns Core](https://banes-lab.com/records/layer/design-patterns-core.md)

Details

Definition
A design pattern that creates a whole family of related objects through one interface, so the members always match.

Requires
[Related Product Variants](https://banes-lab.com/records/lexicon/related-product-variants.md)

Reinforces
[Interchangeability](https://banes-lab.com/records/architecture/interchangeability.md)

Enables
[Family-Level Replacement](https://banes-lab.com/records/lexicon/family-level-replacement.md)

In tension with
[Boilerplate](https://banes-lab.com/records/lexicon/boilerplate.md)

Conflicts with
[Mixed Product Families](https://banes-lab.com/records/lexicon/mixed-product-families.md)

Tensions
[Abstract Factory Pattern / Boilerplate](https://banes-lab.com/records/tension/abstract-factory-pattern-boilerplate.md)

Violated by
incompatible product combinations

Detected by
manual selection of related product classes

Measured by
family mismatch defects

Refactored by
Introduce Abstract Factory

Enforced by
factory conformance tests

Before

```typescript
const store = env === "test" ? new MemoryFooStore() : new SqlFooStore();
const bus = env === "test" ? new MemoryFooBus() : new KafkaFooBus();
```

After

```typescript
interface FooPlatformFactory {
store(): FooStore;
bus(): FooBus;
}
class TestFooPlatformFactory implements FooPlatformFactory {
store() { return new MemoryFooStore(); }
bus() { return new MemoryFooBus(); }
}
```

How it is checked

Checked by
factory conformance tests

Population
Every construction site of the types the pattern governs

Freshness
A verdict stands until a constructor, a variant or the composition root changes

Refusal
The review or the construction test rejects a construction that bypasses the creational owner

Observation
Constructor call sites and their argument counts, read from source

Evidence
None, because the catalog states this check as a class, so a watched run belongs to each system that adopts it

Authoritative side
The creational owner, which every construction site goes through

Depends on
[Related Product Variants](https://banes-lab.com/records/lexicon/related-product-variants.md), [Interchangeability](https://banes-lab.com/records/architecture/interchangeability.md), [Family-Level Replacement](https://banes-lab.com/records/lexicon/family-level-replacement.md)

Shape it refuses
[Mixed Product Families](https://banes-lab.com/records/lexicon/mixed-product-families.md)

### Builder Pattern

- Kind: [pattern](https://banes-lab.com/records/kind/pattern.md)
- Category: [Creational Patterns](https://banes-lab.com/ontology/principles/architecture-category-creational-patterns.md)
- Severity: [recommended](https://banes-lab.com/records/vocabulary/severity-recommended.md)
- Scope: object construction, API
- Layer: [Design Patterns Core](https://banes-lab.com/records/layer/design-patterns-core.md)

Details

Definition
A design pattern that assembles a complex object step by step through named calls and validates it when it is built.

Requires
[Complex Construction](https://banes-lab.com/records/lexicon/complex-construction.md)

Reinforces
[Intent-Revealing Interface](https://banes-lab.com/records/architecture/intent-revealing-interface.md)

Enables
[Valid Object Creation](https://banes-lab.com/records/lexicon/valid-object-creation.md)

In tension with
[Boilerplate](https://banes-lab.com/records/lexicon/boilerplate.md)

Conflicts with
[Telescoping Constructor](https://banes-lab.com/records/lexicon/telescoping-constructor.md)

Tensions
[Builder Pattern / Boilerplate](https://banes-lab.com/records/tension/boilerplate-builder-pattern.md)

Violated by
constructors with many optional params

Detected by
high-arity constructors

Measured by
constructor parameter count

Refactored by
Introduce Builder

Enforced by
API review

Before

```typescript
const foo = new Foo("foo_1", "Foo", [], 0, false, undefined, "draft");
```

After

```typescript
const foo = new FooBuilder()
.withId("foo_1")
.withName("Foo")
.withStatus("draft")
.build();
```

How it is checked

Checked by
API review

Population
Every construction site of the types the pattern governs

Freshness
A verdict stands until a constructor, a variant or the composition root changes

Refusal
The review or the construction test rejects a construction that bypasses the creational owner

Observation
Constructor call sites and their argument counts, read from source

Evidence
None, because the catalog states this check as a class, so a watched run belongs to each system that adopts it

Authoritative side
The creational owner, which every construction site goes through

Depends on
[Complex Construction](https://banes-lab.com/records/lexicon/complex-construction.md), [Intent-Revealing Interface](https://banes-lab.com/records/architecture/intent-revealing-interface.md), [Valid Object Creation](https://banes-lab.com/records/lexicon/valid-object-creation.md)

Shape it refuses
[Telescoping Constructor](https://banes-lab.com/records/lexicon/telescoping-constructor.md)

### Prototype Pattern

- Kind: [pattern](https://banes-lab.com/records/kind/pattern.md)
- Category: [Creational Patterns](https://banes-lab.com/ontology/principles/architecture-category-creational-patterns.md)
- Severity: [contextual](https://banes-lab.com/records/vocabulary/severity-contextual.md)
- Scope: [object_creation](https://banes-lab.com/records/force/object-creation.md), runtime
- Layer: [Design Patterns Core](https://banes-lab.com/records/layer/design-patterns-core.md)

Details

Definition
A design pattern that creates new objects by cloning a prepared template and applying overrides.

Requires
[Cloneable Template Object](https://banes-lab.com/records/lexicon/cloneable-template-object.md)

Reinforces
[Runtime Extensibility](https://banes-lab.com/records/architecture/runtime-extensibility.md)

Enables
[Dynamic Object Creation](https://banes-lab.com/records/lexicon/dynamic-object-creation.md)

In tension with
[Copy Semantics](https://banes-lab.com/records/lexicon/copy-semantics.md)

Conflicts with
[Complex Factory Hierarchies](https://banes-lab.com/records/lexicon/complex-factory-hierarchies.md)

Tensions
[Prototype Pattern / Copy Semantics](https://banes-lab.com/records/tension/copy-semantics-prototype-pattern.md)

Violated by
expensive repeated setup

Detected by
duplicate initialization flows

Measured by
initialization duplication/cost

Refactored by
Introduce Prototype, Add Clone Semantics

Enforced by
clone tests

Before

```typescript
function copyFoo(foo: Foo) {
return new Foo(foo.id, foo.name, [...foo.tags], foo.settings.theme, foo.settings.mode);
}
```

After

```typescript
class FooPrototype {
constructor(private readonly base: Foo) {}
clone(overrides: Partial<Foo> = {}): Foo {
return structuredClone({ ...this.base, ...overrides });
}
}
const template = new FooPrototype(await buildExpensiveFoo());
const draft = template.clone({ name: "quick" });
```

How it is checked

Checked by
clone tests

Population
Every construction site of the types the pattern governs

Freshness
A verdict stands until a constructor, a variant or the composition root changes

Refusal
The review or the construction test rejects a construction that bypasses the creational owner

Observation
Constructor call sites and their argument counts, read from source

Evidence
None, because the catalog states this check as a class, so a watched run belongs to each system that adopts it

Authoritative side
The creational owner, which every construction site goes through

Depends on
[Cloneable Template Object](https://banes-lab.com/records/lexicon/cloneable-template-object.md), [Runtime Extensibility](https://banes-lab.com/records/architecture/runtime-extensibility.md), [Dynamic Object Creation](https://banes-lab.com/records/lexicon/dynamic-object-creation.md)

Shape it refuses
[Complex Factory Hierarchies](https://banes-lab.com/records/lexicon/complex-factory-hierarchies.md)

### Singleton Pattern

- Kind: [pattern](https://banes-lab.com/records/kind/pattern.md)
- Category: [Creational Patterns](https://banes-lab.com/ontology/principles/architecture-category-creational-patterns.md)
- Severity: [discouraged](https://banes-lab.com/records/vocabulary/severity-discouraged.md)
- Scope: [object_creation](https://banes-lab.com/records/force/object-creation.md), lifetime, composition root
- Layer: [Design Patterns Core](https://banes-lab.com/records/layer/design-patterns-core.md)

Details

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

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)

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

Conflicts with
[Global Mutable State](https://banes-lab.com/records/lexicon/global-mutable-state.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)

Violated by
a global mutable instance reached from anywhere

Detected by
static global access to a shared service

Measured by
global-instance reach-in count

Refactored by
Compose Single Instance at the Root, Inject It

Enforced by
composition-root review

Before

```typescript
let instance: FooService | undefined;
function getFooService() { return instance ??= new FooService(); }
```

After

```typescript
class FooService {}
export function composeApp() {
const fooService = new FooService();
return { fooService, fooController: new FooController(fooService) };
}
```

How it is checked

Checked by
composition-root review

Population
Every construction site of the types the pattern governs

Freshness
A verdict stands until a constructor, a variant or the composition root changes

Refusal
The review or the construction test rejects a construction that bypasses the creational owner

Observation
Constructor call sites and their argument counts, read from source

Evidence
None, because the catalog states this check as a class, so a watched run belongs to each system that adopts it

Authoritative side
The creational owner, which every construction site goes through

Depends on
[Single-Instance Need](https://banes-lab.com/records/lexicon/single-instance-need.md), [Controlled Instantiation](https://banes-lab.com/records/lexicon/controlled-instantiation.md), [Shared Resource Access](https://banes-lab.com/records/lexicon/shared-resource-access.md)

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

## Links to

- [pattern](https://banes-lab.com/records/kind/pattern.md)
- [recommended](https://banes-lab.com/records/vocabulary/severity-recommended.md)
- [Object creation](https://banes-lab.com/records/force/object-creation.md)
- [Design Patterns Core](https://banes-lab.com/records/layer/design-patterns-core.md)
- [Creation Variation](https://banes-lab.com/records/lexicon/creation-variation.md)
- [Open/Closed Principle](https://banes-lab.com/records/architecture/open-closed.md)
- [Encapsulation](https://banes-lab.com/records/architecture/encapsulation.md)
- [Polymorphic Construction](https://banes-lab.com/records/lexicon/polymorphic-construction.md)
- [Simplicity](https://banes-lab.com/records/lexicon/simplicity.md)
- [Scattered Construction Logic](https://banes-lab.com/records/lexicon/scattered-construction-logic.md)
- [Registry Pattern](https://banes-lab.com/records/architecture/registry-pattern.md)
- [Factory Pattern / Simplicity](https://banes-lab.com/records/tension/factory-pattern-simplicity.md)
- [contextual](https://banes-lab.com/records/vocabulary/severity-contextual.md)
- [Subclass-Controlled Creation](https://banes-lab.com/records/lexicon/subclass-controlled-creation.md)
- [Deferred Instantiation](https://banes-lab.com/records/lexicon/deferred-instantiation.md)
- [Inheritance Complexity](https://banes-lab.com/records/lexicon/inheritance-complexity.md)
- [Concrete Constructor Coupling](https://banes-lab.com/records/lexicon/concrete-constructor-coupling.md)
- [Factory Method Pattern / Inheritance Complexity](https://banes-lab.com/records/tension/factory-method-pattern-inheritance-complexity.md)
- [Design Review](https://banes-lab.com/records/architecture/design-review.md)
- [Related Product Variants](https://banes-lab.com/records/lexicon/related-product-variants.md)
- [Interchangeability](https://banes-lab.com/records/architecture/interchangeability.md)
- [Family-Level Replacement](https://banes-lab.com/records/lexicon/family-level-replacement.md)
- [Boilerplate](https://banes-lab.com/records/lexicon/boilerplate.md)
- [Mixed Product Families](https://banes-lab.com/records/lexicon/mixed-product-families.md)
- [Abstract Factory Pattern / Boilerplate](https://banes-lab.com/records/tension/abstract-factory-pattern-boilerplate.md)
- [Complex Construction](https://banes-lab.com/records/lexicon/complex-construction.md)
- [Intent-Revealing Interface](https://banes-lab.com/records/architecture/intent-revealing-interface.md)
- [Valid Object Creation](https://banes-lab.com/records/lexicon/valid-object-creation.md)
- [Telescoping Constructor](https://banes-lab.com/records/lexicon/telescoping-constructor.md)
- [Builder Pattern / Boilerplate](https://banes-lab.com/records/tension/boilerplate-builder-pattern.md)
- [Cloneable Template Object](https://banes-lab.com/records/lexicon/cloneable-template-object.md)
- [Runtime Extensibility](https://banes-lab.com/records/architecture/runtime-extensibility.md)
- [Dynamic Object Creation](https://banes-lab.com/records/lexicon/dynamic-object-creation.md)
- [Copy Semantics](https://banes-lab.com/records/lexicon/copy-semantics.md)
- [Complex Factory Hierarchies](https://banes-lab.com/records/lexicon/complex-factory-hierarchies.md)
- [Prototype Pattern / Copy Semantics](https://banes-lab.com/records/tension/copy-semantics-prototype-pattern.md)
- [discouraged](https://banes-lab.com/records/vocabulary/severity-discouraged.md)
- [Single-Instance Need](https://banes-lab.com/records/lexicon/single-instance-need.md)
- [Controlled Instantiation](https://banes-lab.com/records/lexicon/controlled-instantiation.md)
- [Shared Resource Access](https://banes-lab.com/records/lexicon/shared-resource-access.md)
- [Testability](https://banes-lab.com/records/architecture/testability.md)
- [Dependency Injection](https://banes-lab.com/records/architecture/dependency-injection.md)
- [Global Mutable State](https://banes-lab.com/records/lexicon/global-mutable-state.md)
- [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)

## Linked from

- [The layer topology](https://banes-lab.com/ontology/schema/the-layer-topology.md)
- [The membership](https://banes-lab.com/ontology/schema/the-membership.md)
