I'm currently trying to figure out how the Memento Pattern works. And did I stick to the Caretaker class? Is this really important? I mean, I can use Memento without this class. See my code below.
public class Originator { private String state; private Integer code; private Map<String, String> parameters;
Here is the implementation of Memento.
public class Memento { private String state; private Integer code; private Map<String, String> parameters; public Memento(Originator originator) { Cloner cloner = new Cloner(); this.state = cloner.deepClone(originator.getState()); this.code = cloner.deepClone(originator.getCode()); this.parameters = cloner.deepClone(originator.getParameters()); }
This code works great, and Memento works fine.
source share