LearningTech

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:
    def __init__(self):
        pass

    def execute(self):
        print('Executing Memento')