1 00:00:00,720 --> 00:00:07,320 Let's start by having a look at the originator class so we have the state stored as a string and we 2 00:00:07,320 --> 00:00:13,650 have a getter and a setter for the state's property, but also we have the methods for storing the state 3 00:00:13,650 --> 00:00:14,780 in the momentum class. 4 00:00:14,970 --> 00:00:21,930 So as you can see, we have this stored state mental method that will return a new memento and the memento 5 00:00:21,980 --> 00:00:28,330 will receive the state in the constructor to to save it in its in its properties. 6 00:00:28,620 --> 00:00:35,100 So we also have a retrieved state from Memento where we get the memento as a parameter. 7 00:00:35,100 --> 00:00:41,550 And as you can see, we call to get state to get there for the state property from the memento itself. 8 00:00:42,000 --> 00:00:45,310 So let's take a look then at the memento. 9 00:00:45,540 --> 00:00:49,170 So as you can see, we have the same property here called State. 10 00:00:49,500 --> 00:00:57,900 We have the constructor which initializes the state as well, and also to get the get state method, 11 00:00:57,900 --> 00:01:02,330 which will return the current state of of the object. 12 00:01:03,150 --> 00:01:09,180 Of course, we have the caretaker of the caretaker will will store a list of mementos here. 13 00:01:09,660 --> 00:01:13,120 All the mementos will will store a different state. 14 00:01:13,410 --> 00:01:19,980 So as you can see, these are the letters for adding for getting a memento, for retrieving it. 15 00:01:19,980 --> 00:01:20,310 Right. 16 00:01:20,310 --> 00:01:27,810 And also for the forgetting the size of the memento list, which is important for us to in order to 17 00:01:27,810 --> 00:01:34,280 navigate through all of the states that were created previously. 18 00:01:35,370 --> 00:01:41,310 So let's take a look then in the class in the main method here. 19 00:01:41,340 --> 00:01:46,290 So as you can see, we create an originator, we create a caretaker as well. 20 00:01:46,740 --> 00:01:49,880 We set some states to the originator. 21 00:01:49,890 --> 00:01:58,470 We also need to make sure that the caretaker also has those states stored as well, because otherwise 22 00:01:58,470 --> 00:02:05,460 those those states will be lost, will not be stored anywhere as soon as the state will be changed in 23 00:02:05,460 --> 00:02:06,310 the originator. 24 00:02:06,750 --> 00:02:10,790 So you need to make sure that you have this you call this method here as well. 25 00:02:11,790 --> 00:02:14,220 So we we switch to different states here. 26 00:02:14,220 --> 00:02:16,590 As you can see, there are only only four states. 27 00:02:16,590 --> 00:02:24,330 And also we do assist out with the current state of the originator just to make sure that the current 28 00:02:24,330 --> 00:02:27,990 state is the right one, which should be should be for in our case. 29 00:02:27,990 --> 00:02:34,040 And also we do a follow up and we retrieve all the states that were saved in the caretaker. 30 00:02:34,710 --> 00:02:39,150 So you will see that all the states here in our case will be will be saved. 31 00:02:39,150 --> 00:02:46,980 So everything will be retrieved and everything will be printed out in in the council due to this statement 32 00:02:46,980 --> 00:02:47,280 here. 33 00:02:47,580 --> 00:02:48,930 So let's see this in action. 34 00:02:50,470 --> 00:02:55,090 So as you can see, the current status for which is correct, because the last one was was the fourth 35 00:02:55,090 --> 00:03:03,790 state and we have three states because the fourth one wasn't added in the caretaker because it's the 36 00:03:03,790 --> 00:03:04,390 current one. 37 00:03:04,390 --> 00:03:06,880 We don't need to store the current one. 38 00:03:07,210 --> 00:03:14,560 So, as you can see, all the three previous states were were saved and retrieved by our method from 39 00:03:14,560 --> 00:03:15,310 the caretaker. 40 00:03:16,210 --> 00:03:16,720 All right. 41 00:03:16,960 --> 00:03:21,550 So this is it for this tutorial. 42 00:03:21,550 --> 00:03:26,260 Join me in the next one where we are going to discuss about the observer pattern.