The vehicle part interface will have only one method, which will accept an object of the type vehicle
park visitor.
Let's take a look at the second interface, which is the vehicle park visitor, which has also only
one method, which is central to the visitor pattern, because using this method, you will be able
to modify the behavior of the element class, which is in our case, which is the implementation of
the vehicle part interface.
So the vehicle parts basically allow let's take a look at the parts that are implementing the vehicle
park interface so you can see the implementation of the equipment and for the car by the end.
This is actually the same implementation for all the classes, for all the classes that are implementing
this vehicle, the interface.
And you can see that inside we use the object vehicle park visitor, which we handle as a parameter
of this method here, and we call the visit method.
And we also supply this object to to this to this method.
Let's take a look at the implementation for the visitor interface.
So we have only one class, as I said, but we can have multiple, depending on how many algorithms
we want to apply to perform on on the element classes, which are the vehicle parts classes.
And here we are just doing a system of Quintel and we are displaying the the vehicle part that is visited
basically by displaying it's the name of the the name of each class.
Let's take a look at the main method here.
And we can see that we instantiate a new vehicle using those vehicles.
And by the way, I haven't touched upon the vehicle class.
This is pretty important, basically.
So we have here an array of vehicle parts because this is what the vehicle is, right?
It's it's a collection of of elements of of components.
When put together, they assemble a vehicle.
And here in the constructor we can see that we instantiate the vehicle.
And also we we store all the components that are available in our vehicle.
Part array here.
The accept method for this one will we'll just iterate through the vehicle part array and we'll accept
each vehicle part and then will supply this vehicle park visitor, which is sent to this method as a
parameter.
And here, of course, we call the visit method using this this object here.
And let's get back to our class here.
So we instantiate a new vehicle.
So basically we are creating a new vehicle that is form of these three parts that we see here.
And we call the excitement that this is what it takes.
And of course, we instantiate a new vehicle, part show visitor, which is our algorithm that is applied,
that is performed on this on this vehicle element object.
And as you may have guessed, this should output the names of the components that are inside this vehicle
that will use to assemble these vehicles.
So let's see this in action.
So as you can see, when we execute it, we just see here the implementation of this visit method that
is inside the show visiter class, which will display in the console each name the names of each component
that are forming this this vehicle class.
All right.
I know this can be a bit complex, but actually it's a pretty, pretty easy concept.
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
going to be a useful tool whenever you want to modify the behavior of an object at runtime, whenever
you want to supply a new algorithm for your object, for actions and so on and so forth.
All right.
Thank you for watching the series.
This was the last story of the design pattern series.
I will be creating other other series as well.
My plan is to create one for creating an application, a mobile application using ANGULAR with Ionic
framework.
So I will start working on that.
And if you liked those videos, if you find them useful and I hope you.
Please leave me a rating, please leave some feedback so that I can improve for the next videos.
Thanks again for watching this and see you in the next series.