Behavioral

Memento

Description

Lets you save and restore the previous state of an object without revealing the details of its implementation.

Where to use

  • Snapshots.
  • \n
  • Game Save Systems.
  • \n
  • Undo features.

Real World Example

A text editor saves a snapshot of the document state before every change.

Code Example

class Memento:\n    def __init__(self):\n        pass\n\n    def execute(self):\n        print('Executing Memento')