Imagine for a second that I'm implementing the Memento Pattern, using the following classes.ClassesAn Originator class that has public and private, properties and fields respectivelyA Memento class that has many properties/fields representing state of OriginatorA CareTaker class that acts on an instance of Originator, and saves a list of Mementos representing the Originator's state. Using the example classes above, is there an objective reason to use one of the following solutions over the other? The premise here is that I need to expose a few properties that partially represent the state of the Originator.Solution #1Properties and fields representing state are duplicated across Originator & MementoOriginator has a CreateMemento method that initializes a new Memento with all of the shared properties/fields between the twoOriginator has a SetMemento method that sets Originator's properties/fields to those that correspond with Memento'sSolution #2Originator has an instance of Memento, representing Originator's current stateOriginator exposes as properties, the necessary properties/fields of it's Memento, using the getters/setters to update the mementoOriginator doesn't have it's own copy of properties/fields representing its state, instead it uses it's Memento as a backing store.I understand that ideally there should be yet another class OriginatorState, that Originator & Memento both have instances of, but I'm not asking about which classes to create. I'm asking which class holds the information of the current state of the Originator. Both the Originator and the Memento? Just the Memento? or the Originator vicariously through the Memento as in Solution #2?
Who is the Owner of Information? Memento vs. Originator
design;design patterns;object oriented;object oriented design;code quality