When talking about mutability Joshua Bloch in Effective Java states, “Classes should be immutable unless there’s a very good reason to make them mutable”. An immutable class is one whose external state cannot change once created. Immutable classes lend themselves to a functional approach where methods return the result of applying a function to the operand without modifying it.
Joshua provides five rules for class immutability:
- Don’t provide methods that modify the object’s state