Change Reference to Value

Removes smells
Symptom

A class with public mutable fields used by many consumers; the agent reasoning about any read must consider every other writer.

Goal

The object is immutable + equal-by-content; the agent reasons about value semantics without modeling write timing.

Before the refactoring

class Phone {
constructor() { this.area = null; this.number = null; }
}
phone.area = '617';

After the refactoring

class Phone {
constructor(area, number) { this._area = area; this._number = number; }
area() { return this._area; }
number() { return this._number; }
withArea(area) { return new Phone(area, this._number); }
}
Example source: Illustrative example written for this site, not a quotation from any source.
Pressure

The agent must trace every writer to model state at any read; concurrent reasoning is practically impossible.

Tradeoff

Comparison semantics shift from identity to equality; every call site that depended on === or identity caches needs the agent's review and update.

Relief

Concurrency hazards disappear; the type system can mark fields readonly; the agent reasons about the object as a stable value.

Trap

Switching domain entities (Customer, Account) to value semantics strips the identity the agent's consumers depended on — equality replaces 'this specific thing' with 'anything that looks like it'.