Skip to content
Commitwise
Menu

Abstract Factory pattern

An interface for creating a family of related objects, with one concrete factory per family, so parts from different families are never mixed.

Definition

The interface has one creation method per product; each concrete factory (sandbox or live, brand A or brand B) creates products that work together. The app chooses one factory at startup and passes it in, and callers ask it for everything they need. Adding a family is one new class; adding a product type changes every factory. DI modules per build flavor or Spring profile are abstract factories in another form.

In practice

PaymentKit creates a client, a tokenizer and a webhook verifier; SandboxPaymentKit and LivePaymentKit each create a matching set.

Related terms

Esc

Type to search the whole site.