Suppose you were making a card game with other people and want to make it as bug free as possible. One consequence of this is making sure that object data cannot be corrupted.
Suppose you have a Game and it holds a Deck. Game obviously modifies Deck and so Deck has methods for that manipulation. However, using the methods incorrectly could corrupt the data. Usually to avoid this, you would encapsulate the object. However, for debugging reasons, you need outside access to Deck’s cards has. But exposing Deck would expose those manipulation methods and allow outsiders to corrupt the data. So, how do you expose Deck’s cards, and allow ONLY the Game to manipulate the Deck?