Remove Setting Method

Compare
Symptom
Human

A class with setters whose values should only be set at construction — every late-mutation site is using the setter for what should be a one-shot assignment.

Agent

The agent finds setters on a class whose values should only be set at construction; every late-mutation site is using setters for one-shot assignment.

Goal
Human

Fields whose values should only be set at construction lose their setters; callers either construct a new object or call a domain method that changes the field as a side effect of doing real work.

Agent

Construction is the only path to setting these fields; the agent reasons about the object as immutable-after-construction.

Before the refactoring

class Person {
setName(n) { this._name = n; }
}

After the refactoring

class Person {
constructor(name) { this._name = name; }
name() { return this._name; }
}
Example source: Illustrative example written for this site, not a quotation from any source.
Pressure
Human

Late mutations introduce timing-dependent bugs; consumers can't trust the object's invariants between operations; immutability arguments break.

Agent

Late mutations break the agent's reasoning about invariants between operations; the agent must trace every setter call to verify timing assumptions.

Tradeoff
Human

Removing a setter forces every legitimate update through a more meaningful method — verify there's a domain action behind every setter call before deleting it.

Agent

Removing a setter forces every legitimate update through a more meaningful method; the agent must verify each setter call has a domain action that justifies replacing it.

Relief
Human

Immutable-by-default classes; bugs from late mutation vanish; the API expresses what users can actually do.

Agent

The agent reasons about the class as immutable-after-construction; bugs from late mutation vanish; the API expresses what users can actually do.

Trap
Human

Removing setters that genuinely encode a meaningful state change — a `markPaid()` setter that mutates `paidAt` and `status` together — without replacing them with a richer domain method.

Agent

Removing setters that meaningfully encoded a domain state change — like markPaid() coordinating paidAt+status — without replacing them with the equivalent domain method strips the semantic anchor.