SOFTWARE ENGINEERING

SOFTWARE DESIGN

DESIGN PATTERNS

Question [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
In which pattern you can produce snapshots of the object’s state without violating its encapsulation?
A
Mediator
B
Memento
C
State
D
Visitor
Explanation: 

Detailed explanation-1: -The memento pattern allows one to capture the internal state of an object without violating encapsulation such that later one can undo/revert the changes if required.

Detailed explanation-2: -The Memento Design Pattern offers a solution to implement undoable actions. We can do this by saving the state of an object at a given instant and restoring it if the actions performed since need to be undone. Practically, the object whose state needs to be saved is called an Originator.

Detailed explanation-3: -The Memento pattern is also known as Token. Undo or backspace or ctrl+z is one of the most used operation in an editor. Memento design pattern is used to implement the undo operation. This is done by saving the current state of the object as it changes state.

Detailed explanation-4: -Example. The Memento captures and externalizes an object’s internal state so that the object can later be restored to that state. This pattern is common among do-it-yourself mechanics repairing drum brakes on their cars. The drums are removed from both sides, exposing both the right and left brakes.

There is 1 question to complete.