Create history of states in Java -


I have a Java application in which more states than some tasks, which I can reload in order to restore Need to save a history in a certain action state in other words, I have a screen in which there is a state with it and I have to store it with any changes in history so that I can at any time return the status of the screen I find Thapit. This is a kind of 'undo' but not at all, as the difference between the two states can be very large and there are no well-defined verbs which make changes in the states.

Explain me with an example: The original screen state may include a single map in the state with the key "Key 2" with key "Key 1" and "Object 2" and " Object 1 "is the reference. The map in the State B is still a reference to "object 1", but "object 2" has been modified and an "object 3" has been added. Now I need to be able to return to State A, which will include excluding Object 3 and restoring object 2 in its previous state. I can not define any custom "undo actions" because I do not know what changes were made in object 2 or what type of object 2 is. Also, because the reference in A2 and B remains the same for object 2, those changes are displayed in State A, so that object 2 is not so.

I know the best solution is to implement the clone, but as I need to support all types of objects (including preferences and standard collection), it is not possible. I had thought about using serials, where I serialize the map as a state infection and then it needs to be canceled when it is needed, but it seems like a very ugly solution. .

Do anyone have any other ideas? Thanks, Restarto

Have you tried it? This is especially well-defined for your problem. From Wikipedia:

The memento pattern is a software design pattern that provides the ability to restore an object to its previous state (undo by rollback).

There is also a section on the same page, since you have told that it is in Java.


Comments