Move Field

Compare
Symptom
Human

A field on class A whose value is determined by data on class B (`customer.discountRate` set from `customer.plan.kind`) — the field belongs with the data it's derived from.

Agent

The agent finds a field on class A whose value is determined by data on class B; reasoning about the field's value requires loading B to verify the derivation.

Goal
Human

Each field belongs to the class that owns its lifecycle; cross-class reaching disappears.

Agent

Each field lives in the class that determines its value; reading the field and reading the data that determines it happen in the same class file.

Before the refactoring

class Customer {
plan;
discountRate;
}
// every customer in a given plan gets the same rate:
customers.forEach(c => c.discountRate = c.plan.kind === 'gold' ? 0.15 : 0.05);

After the refactoring

class Plan {
kind;
discountRate;
}
class Customer { plan; }
customer.plan.discountRate;
Example source: Illustrative example written for this site, not a quotation from any source.
Pressure
Human

Every consumer of A must maintain the cross-class invariant; refactoring B's data shape breaks A in non-obvious ways; the field's true owner is invisible.

Agent

Every consumer must maintain the cross-class invariant; the agent verifying any change must coordinate updates across both classes.

Tradeoff
Human

Every reader of the original class now reaches across the new class boundary — coupling drops at the field's new home but reappears at each consumer.

Agent

Every previous reader of the field now loads the new owner class to read it; tokens that previously stayed in one file now span two, and the agent follows the new boundary at every read site.

Relief
Human

Class boundaries align with data ownership; mutations are local; refactoring becomes safer.

Agent

Mutations to the field stay inside the class that determines its value; the agent reads one class file to predict both the field's value and the data that drives it.

Trap
Human

Moving fields whose presence on the original class is part of the class's identity — even when the value derives elsewhere, moving the field can break consumer expectations.

Agent

Moving fields purely on derivation grounds — without checking whether the original class's identity depends on the field's presence — breaks consumer expectations the agent didn't model.