From the course: Python: Advanced Design Patterns

Unlock the full course today

Join today to access over 23,200 courses taught by industry experts.

Memento

Memento

- [Instructor] It is often necessary to revert an action when using a system. For example all of us are familiar with ubiquitous undo shortcuts in our word processing programs. In the case of database applications, rollback is an essential option because irreversible changes can do humongous damage to both your tasks at hand, and future objectives. If you're looking for a design solution, to this type of programming need, memento is a perfect behavioral design pattern for you. This pattern allows you to capture the internal state of an object at a certain point in time, and to restore that same state later in the future if necessary. An object can take on this task in addition to its core mission, but this will make it bulkier and more complex. A better solution is to introduce a new object dedicated to storing the history of transactions associated with the other object. Note that the goal here is not to store every single property of a target object, but to get only those relevant…

Contents