Repaso
EspaƱol
Design & PracticesIntermediateDP-06

When is Builder a better fit than Factory?

Options

  1. When you need one of several subclasses chosen at runtime
  2. When an object has many optional parts assembled step by step (Correct option)
  3. When you need exactly one instance in the whole program
  4. When existing objects must be cloned instead of created

Answer

When an object needs many optional parts assembled step by step

Why

A Factory decides WHICH type of object to create (e.g. make_notifier("sms") returns an SmsNotifier).

A Builder handles HOW to assemble one complex object step by step, when it has many optional settings (e.g. an HTTP request with headers, timeout, retries).

In Python, keyword arguments with defaults often replace simple builders.

Remember

Factory = which object. Builder = how to assemble it.

Key terms

Practice this question in Repaso