Let's start by having a look at the originator class so we have the state stored as a string and we
have a getter and a setter for the state's property, but also we have the methods for storing the state
in the momentum class.
So as you can see, we have this stored state mental method that will return a new memento and the memento
will receive the state in the constructor to to save it in its in its properties.
So we also have a retrieved state from Memento where we get the memento as a parameter.
And as you can see, we call to get state to get there for the state property from the memento itself.
So let's take a look then at the memento.
So as you can see, we have the same property here called State.
We have the constructor which initializes the state as well, and also to get the get state method,
which will return the current state of of the object.
Of course, we have the caretaker of the caretaker will will store a list of mementos here.
All the mementos will will store a different state.
So as you can see, these are the letters for adding for getting a memento, for retrieving it.
Right.
And also for the forgetting the size of the memento list, which is important for us to in order to
navigate through all of the states that were created previously.
So let's take a look then in the class in the main method here.
So as you can see, we create an originator, we create a caretaker as well.
We set some states to the originator.
We also need to make sure that the caretaker also has those states stored as well, because otherwise
those those states will be lost, will not be stored anywhere as soon as the state will be changed in
the originator.
So you need to make sure that you have this you call this method here as well.
So we we switch to different states here.
As you can see, there are only only four states.
And also we do assist out with the current state of the originator just to make sure that the current
state is the right one, which should be should be for in our case.
And also we do a follow up and we retrieve all the states that were saved in the caretaker.
So you will see that all the states here in our case will be will be saved.
So everything will be retrieved and everything will be printed out in in the council due to this statement
here.
So let's see this in action.
So as you can see, the current status for which is correct, because the last one was was the fourth
state and we have three states because the fourth one wasn't added in the caretaker because it's the
current one.
We don't need to store the current one.
So, as you can see, all the three previous states were were saved and retrieved by our method from
the caretaker.
All right.
So this is it for this tutorial.
Join me in the next one where we are going to discuss about the observer pattern.