jargon

Design patterns·Objects, messages and the principles

you handed the object a list, changed your list afterwards, and the object's state changed with it.

Defensive copy

Also calledprotective copy, copy on the way in

Copying a mutable argument on the way in, or a mutable field on the way out, so a caller cannot reach past the interface and change your state. It is the price of encapsulation in a language with mutable collections and shared references. The alternative that removes the need entirely is immutability, which is one of the strongest practical arguments for it.

Commonly confused with