advanced

Abstract Factory

Create families of related objects behind one interface when products must stay compatible across themes, platforms, or adapters.

Abstract Factory creates families of related objects—UI widgets, cloud resources, database adapters—that must stay compatible within a theme or platform. Clients work with factory interfaces and product abstractions without knowing concrete vendors. Use it when switching entire stacks together matters more than swapping one class.

On interviews: explain the difference from Factory Method and Builder. A classic example is cross-platform UI kits or themed document exporters.

Common pitfalls: over-engineering when only one product varies; factories that become god-objects; leaking concrete product types through return signatures.

The trade-off is flexibility versus complexity—know when the simpler path is enough.

Checklist:

  • Products in a family share compatibility constraints.
  • Client code never names concrete vendors.
  • Switching families is a configuration change.
  • Keep family size small and cohesive.