Compare
Symptom
Human

Object creation directly via `new Class(...)` where the construction logic needs validation, subclass selection, or instance caching but the constructor can't express any of it.

Agent

The agent finds constructors used directly where construction needs validation, subclass selection, or caching — none of which constructors can express.

Goal
Human

Object creation goes through a named function that can validate, choose subclasses, or return cached instances.

Agent

Construction goes through a named factory the agent can extend with validation, polymorphism, or caching as one location.

Before the refactoring

const employee = new Employee(name, 'engineer', salary);

After the refactoring

function createEngineer(name, salary) {
return new Employee(name, 'engineer', salary);
}
const employee = createEngineer(name, salary);
Example source: Illustrative example written for this site, not a quotation from any source.
Pressure
Human

Constructors can't validate, return subclasses, or cache; consumers either accept the limitation or scatter pre-construction logic at every call site.

Agent

The agent's reasoning about construction must consider pre-construction logic scattered at every call site; constructors hide the capability for the patterns the code actually needs.

Tradeoff
Human

Hides the actual class from callers — the factory's name must still express the produced shape clearly.

Agent

The factory hides the actual class from callers; the agent must ensure the factory's name still expresses the produced shape clearly or call sites become opaque.

Relief
Human

Construction can vary per case; consumers don't depend on which concrete class they're getting.

Agent

The agent extends construction in one place; consumers don't depend on which concrete class they're getting.

Trap
Human

Wrapping every constructor in a factory function for principle — adds a layer of indirection without buying validation, polymorphism, or caching capability.

Agent

Wrapping every constructor in a factory adds an indirection layer the agent must navigate without buying any new construction capability.