1 00:00:00,800 --> 00:00:06,890 The vehicle part interface will have only one method, which will accept an object of the type vehicle 2 00:00:06,890 --> 00:00:07,710 park visitor. 3 00:00:08,420 --> 00:00:14,390 Let's take a look at the second interface, which is the vehicle park visitor, which has also only 4 00:00:14,390 --> 00:00:19,970 one method, which is central to the visitor pattern, because using this method, you will be able 5 00:00:19,970 --> 00:00:27,950 to modify the behavior of the element class, which is in our case, which is the implementation of 6 00:00:27,950 --> 00:00:29,930 the vehicle part interface. 7 00:00:30,230 --> 00:00:35,960 So the vehicle parts basically allow let's take a look at the parts that are implementing the vehicle 8 00:00:35,960 --> 00:00:42,150 park interface so you can see the implementation of the equipment and for the car by the end. 9 00:00:42,560 --> 00:00:48,350 This is actually the same implementation for all the classes, for all the classes that are implementing 10 00:00:48,350 --> 00:00:50,120 this vehicle, the interface. 11 00:00:50,330 --> 00:01:00,170 And you can see that inside we use the object vehicle park visitor, which we handle as a parameter 12 00:01:00,170 --> 00:01:03,950 of this method here, and we call the visit method. 13 00:01:03,950 --> 00:01:09,870 And we also supply this object to to this to this method. 14 00:01:10,670 --> 00:01:15,530 Let's take a look at the implementation for the visitor interface. 15 00:01:15,770 --> 00:01:21,200 So we have only one class, as I said, but we can have multiple, depending on how many algorithms 16 00:01:21,200 --> 00:01:29,500 we want to apply to perform on on the element classes, which are the vehicle parts classes. 17 00:01:29,900 --> 00:01:40,040 And here we are just doing a system of Quintel and we are displaying the the vehicle part that is visited 18 00:01:40,040 --> 00:01:44,370 basically by displaying it's the name of the the name of each class. 19 00:01:45,140 --> 00:01:47,840 Let's take a look at the main method here. 20 00:01:47,840 --> 00:01:54,320 And we can see that we instantiate a new vehicle using those vehicles. 21 00:01:54,470 --> 00:01:59,320 And by the way, I haven't touched upon the vehicle class. 22 00:01:59,330 --> 00:02:00,820 This is pretty important, basically. 23 00:02:01,100 --> 00:02:06,460 So we have here an array of vehicle parts because this is what the vehicle is, right? 24 00:02:06,470 --> 00:02:11,830 It's it's a collection of of elements of of components. 25 00:02:12,200 --> 00:02:14,540 When put together, they assemble a vehicle. 26 00:02:14,780 --> 00:02:20,870 And here in the constructor we can see that we instantiate the vehicle. 27 00:02:22,010 --> 00:02:28,040 And also we we store all the components that are available in our vehicle. 28 00:02:28,040 --> 00:02:29,000 Part array here. 29 00:02:29,480 --> 00:02:37,850 The accept method for this one will we'll just iterate through the vehicle part array and we'll accept 30 00:02:37,850 --> 00:02:47,870 each vehicle part and then will supply this vehicle park visitor, which is sent to this method as a 31 00:02:47,870 --> 00:02:48,430 parameter. 32 00:02:48,680 --> 00:02:55,940 And here, of course, we call the visit method using this this object here. 33 00:02:56,270 --> 00:02:59,630 And let's get back to our class here. 34 00:02:59,630 --> 00:03:01,210 So we instantiate a new vehicle. 35 00:03:01,220 --> 00:03:07,160 So basically we are creating a new vehicle that is form of these three parts that we see here. 36 00:03:07,490 --> 00:03:11,180 And we call the excitement that this is what it takes. 37 00:03:11,180 --> 00:03:18,530 And of course, we instantiate a new vehicle, part show visitor, which is our algorithm that is applied, 38 00:03:18,530 --> 00:03:22,730 that is performed on this on this vehicle element object. 39 00:03:23,120 --> 00:03:31,070 And as you may have guessed, this should output the names of the components that are inside this vehicle 40 00:03:31,070 --> 00:03:33,110 that will use to assemble these vehicles. 41 00:03:33,110 --> 00:03:35,580 So let's see this in action. 42 00:03:36,080 --> 00:03:45,590 So as you can see, when we execute it, we just see here the implementation of this visit method that 43 00:03:45,590 --> 00:03:55,040 is inside the show visiter class, which will display in the console each name the names of each component 44 00:03:55,610 --> 00:03:59,340 that are forming this this vehicle class. 45 00:04:00,560 --> 00:04:01,100 All right. 46 00:04:01,730 --> 00:04:08,260 I know this can be a bit complex, but actually it's a pretty, pretty easy concept. 47 00:04:08,750 --> 00:04:18,240 It's not a very used you'll not encounter this pattern very often in in any code base, but it's a it's 48 00:04:18,260 --> 00:04:23,960 going to be a useful tool whenever you want to modify the behavior of an object at runtime, whenever 49 00:04:23,960 --> 00:04:29,280 you want to supply a new algorithm for your object, for actions and so on and so forth. 50 00:04:30,230 --> 00:04:30,770 All right. 51 00:04:30,890 --> 00:04:33,350 Thank you for watching the series. 52 00:04:33,680 --> 00:04:37,070 This was the last story of the design pattern series. 53 00:04:37,910 --> 00:04:42,190 I will be creating other other series as well. 54 00:04:42,890 --> 00:04:51,200 My plan is to create one for creating an application, a mobile application using ANGULAR with Ionic 55 00:04:51,320 --> 00:04:52,010 framework. 56 00:04:52,370 --> 00:04:54,110 So I will start working on that. 57 00:04:54,500 --> 00:05:00,200 And if you liked those videos, if you find them useful and I hope you. 58 00:05:00,950 --> 00:05:08,510 Please leave me a rating, please leave some feedback so that I can improve for the next videos. 59 00:05:10,870 --> 00:05:16,210 Thanks again for watching this and see you in the next series.