Defensive copying prevents external changes by providing copies of mutable objects.
By returning a copy of a mutable object, such as a list of customer orders, you ensure that changes made by the caller do not affect the internal state of the class. This maintains data integrity, especially in systems like e-commerce platforms where data consistency is vital.
Additional Notes
Why is defensive copying crucial for internal structures?