Let's start by looking at the machine interface here.
So this is the component that we see in our diagram.
It has only one function that one and only one method that will return the street to us.
And here is the implementation of the machine.
I decided to go it with colors because it's a good example for the decorator partner.
You can decorate a car with several functionality, several several features.
So it's easier to understand using this example.
So we just invented this operation method and we only risky work car.
You will see.
You will see why.
And on the other side, we have the decorator, the car decorator abstraction in the form of an abstract
class which implements the same machine interface.
We have a machine object here.
This doesn't need to be encapsulated, meaning that it doesn't have to have private access modifier
because you will need this object in the concrete decorator's that we will implement.
And here we have the constructor.
We will take a machine as an argument and we set the machine, the property of this decorator with this
machine argument and the operation will return.
What the machine wants to do, operation implementation of the machine will return.
So this is very straightforward.
This these are these two of the navigation and the parking assistant are the concrete decorators that
we have.
So as you can see, it extends the navigation, extends the car decorator class.
The constructor is basically the call to the super method, the super constructor and the operation
will return the result of the machine, the operation, but also plus navigation.
So basically, we are adding a new feature to the to the car, which is to our base object.
And the same applies for the parking system as well.
So as you can see, the same code, but instead of adding navigation, we are the parking system and
the class which contains our main method is looking like this.
We basically create the new machine object with the following implementation.
So basically we are adding all the decorators in order to create a car, which parking assistant and
navigation.
So this the system, although through the lens, should output what the machine looks like, what the
what are the features that the machine has.
So let's run this.
So as you can see, we have the base class near the base object, which is a car, and we add the parking
incident, the parking assistant and a navigation features to it.
So basically, this is the stuff that's about it.
This is how you create this is how you implement the decorator pattern in your code.
It's always helpful to have this pattern whenever you want to decorate an object with additional additional
stuff, additional features.
Right.
So in this way, you won't affect your base object.
You won't affect the structure of the base object.
But also you can add at the same time, you can add new functionalities, new features, and each class,
each class that you add will be responsible of each feature.
So it's actually very, very straightforward.
But like I said in the previous video, the downside is that you will have a lot of classes.
If you have a complex object, like a car, for example, you will have a lot of objects that a lot
of classes that you you need to create for each feature because a car has a lot of features.
So if you want to be granular about it, then you will have to add you have to transpose each feature
of a car into a class which will increase the volume of your code.
That's it about the decorator pattern.
Join me in the next story of where we are going to discuss about the facade pattern.
So, so and I story.