Defensive copying prevents external changes by returning copies of mutable objects.
When exposing a mutable object, returning a defensive copy ensures that the caller receives a separate instance that doesn't affect the original. This is crucial in maintaining object integrity. In an e-commerce system, returning a defensive copy of a customer address list prevents external code from altering the addresses directly.
Additional Notes
How does defensive copying protect object integrity?