Design Patterns interview question · Most asked

Compare Factory Method, Abstract Factory and Builder.

Summary

Factory Method creates one product, with the concrete class chosen by a subclass; Abstract Factory creates a matching family of related products through one factory object; Builder creates one complex product step by step with validation at the end.

Longer Answer

Choose Factory Method (or a simple factory) when the question is "which class?"; Abstract Factory when several objects must match (theme widgets, vendor drivers); Builder when the question is "how do I assemble this complex object readably?" (many optional parts, invalid combinations).

They combine: an abstract factory can use builders internally, and a builder can be returned by a factory.

Key Points

  • Factory Method: which class, via subclass.
  • Abstract Factory: matching families.
  • Builder: step-by-step assembly.

Deep dive: Design Patterns, Explained Simply: Choosing the Right Pattern

Explanation

What interviewers look for

The question each pattern answers, with examples.

More most-asked Design Patterns questions

← All Design Patterns questions