DevPrep

All topics › Design patterns

Abstract Factory

Middle PRO

Essence

Abstract Factory is a creational pattern: an interface for creating a family of related objects without naming their concrete types. The client receives a factory and asks it for "a button", "a background", "a font" without knowing whether it is the light theme or an accessibility theme. The key guarantee is that objects from one factory are compatible with each other: you cannot accidentally mix a light background with dark-theme text.

The rest of this answer, with code and interview follow-ups, is in the DevPrep app.

Read the full answer in DevPrep

Practice this before your interview

DevPrep turns these answers into one-minute challenges: what does this code print, find the bug, mock interviews. One challenge a day.

Get DevPrep on the App Store