The Memento design pattern provides a solution:
Define Originator and Memento objects
so that an originator saves/restores its internal state to/from a memento.
Describing the Memento design in more detail is the theme of the following sections.
See Applicability section for all problems Memento can solve.