Controlling how objects are made.
WHAT PROBLEM THEY ADDRESS
Creating objects in a way that is flexible, testable and not scattered throughout the code.
WHAT A FACTORY DOES
Encapsulates the decision about which concrete type to create.
When it helps: when the type depends on conditions, or may change.
WHAT A BUILDER DOES
Constructs a complex object step by step.
When it helps: when there are many optional parameters, avoiding constructors with long argument lists.
WHAT A SINGLETON DOES
Ensures one instance exists.
WHY IT IS CONTROVERSIAL
It introduces global state, makes testing difficult, and hides dependencies.
WHAT TO PREFER INSTEAD
Passing the instance in, so the dependency is visible and replaceable.
WHAT DEPENDENCY INJECTION IS
Supplying a component's dependencies rather than having it create them.
WHY IT MATTERS MOST
It is what makes code testable, because dependencies can be substituted.
WHAT TO RECOGNISE
Much of creational patterns amounts to not creating dependencies inside the things that use them.
WHAT TO AVOID
Factories producing one type Builders for objects with two fields