Now, we will now get to know the Memento Design Pattern.
Sometimes it’s necessary to record the internal state of an object. This is required when implementing checkpoints and “undo” mechanisms that let users back out of tentative operations or recover from errors. You must save state information somewhere, so that you can restore objects to their previous conditions. But objects normally encapsulate some or all of their state, making it inaccessible to other objects and impossible to save externally. Exposing this state would violate encapsulation, which can compromise the application’s reliability and extensibility. The Memento pattern can be used to accomplish this without exposing the object’s internal structure.
Via a real life example, you will learn how and when the Memento design pattern should be used and how to structure your code in order to implement it. You will see how it can lead to elegant solutions to code problems.