Mistake: treating a value object as mutable state. Immutable data keeps its value fixed after construction. For a Rational number, mutators can break the class invariant and make every client reason about invalid intermediate states. Remove setters when the problem does not require mutation. section 7.4
Make Rational values stable
A naïve Rational class exposes setNumerator and setDenominator, uses floating-point members, and permits a zero denominator. A safer interface stores integer components, validates the denominator during construction, reduces the value internally, and returns new Rational objects from addition and multiplication rather than altering an operand. section 7.4
When reviewing a value-like class:
- Ask whether the represented value can ever change. section 7.4
- Hide helpers such as gcd and reduce when clients do not need them. section 7.4
- Name operations clearly and make their result behavior intuitive. section 7.4























