Okay, so we had this very complex example of code here, right where we had the payment servers.
We had the PayPal processor, which is an AI payment processor or implements it.
Same for credit card processor.
But then we also had the AI payment processor and then we had polymorphism.
And like all of these things came together and it was whew, Holy moly.
I think it was the toughest video in terms of depth of content that we had so far.
So now let's try to understand it in a visual way.
Okay.
Let's really break it down and see how the things are interconnected.
So we have interfaces and polymorphism in our payment process.
So we have three things.
We have our AI payment processor interface.
We have our payment service class and we have our program class.
So let's look at the AI payment processor.
We use the AI payment processor and created two classes of it or two classes that implement it.
So we have the credit card processor which implements and processes the credit card payments.
And we have the PayPal processor which implements and processes PayPal payments.
Then we have this payment service which uses an AI map processor to process the payments.
So the AI map processor is this one here, right.
This one right here.
So it doesn't care what AI payment processor it gets.
So that's where either a credit card processor or a PayPal processor can be used.
And what it does is it processes order payments.
So it delegates to the AI payment processor.
So the actual execution, how it's done, so to speak, is not managed by our payment service, but
it is done by the AI payment processor implemented class.
So the class that implements this AI payment processor so the payment service doesn't bother.
It doesn't care which one of those is used.
And then we have our program here which sets up and uses this payment service that we created this one
right here.
And then it initiates the payment process with different processors.
So either the credit card processor or the PayPal processor.
So this is a visualization of what's going on inside of our project here okay.
So we have this AI payment processor which just says okay you know what.
If you implement me follow this guideline as to what core information about the methods should be implemented,
such as it doesn't return anything and it takes a decimal value.
Then any class that implements this AI payment processor interface needs to implement this method.
But it's in its own way.
We have two different types of it.
We have the PayPal processor, which implements the AI payment processor, and we have the credit card
processor that does that.
So then we have this payment service which is really key here.
Right.
Because first it has this read only private field which really just makes sure okay, we get an AI payment
processor.
And that AI payment processor then is delivered through the constructor.
So whenever we pass an AI payment processor, implemented class or implementing class as the processor
so it doesn't care which of the classes it is, is it the PayPal processor?
Is it the credit card processor?
Is it a fourth, third, fifth?
Whatever processor.
It just cares that it is implementing this interface because it knows it can trust the class that implements
this interface to have a way to process payments.
That's it's a contract that is signed, so to speak.
It knows, okay, whoever is the processor, whatever class it is, it has signed the contract with
this interface that it's going to do what it's supposed to do in order to manage how a processor, the
payment is processed.
Okay.
And then we have this process order payments, which is a method that we then can call and pass in the
decimal amount.
But the actual way how this payment is processed, we give over to the processor.
We don't handle ourselves.
We just say, hey processor, I know that you have this method called process payment.
And now depending on what kind of processor you are, are you a PayPal processor?
Are you a credit card processor you have your way of implementing?
I don't care, I just give you the information that you need in order to do your thing, and that is
the amount which is a decimal.
And then the payment processor does the rest.
So this now is pretty abstract, right?
But at the same time it allows us to use this.
Morphism here.
So here is where the polymorphism comes up.
This is the polymorphism line okay.
This is your polymorphism where we are treating the credit card processor like an eye payment processor
because it is implementing the eye payment processor.
This class right.
The credit card processor.
It's like we saw earlier with our animal and dog.
So the dog is inheriting from animal.
So in our case the credit card processor is implementing not inheriting.
But it's quite close from eye payment processor.
And then we can pass that to our payment service which just said I need a payment or an eye payment
processor in the constructor when an object of myself is created.
So when an object of this class here is created, and then I can do the processing because I just give
over the responsibility to whoever knows how to do it.
And in this case, it's going to be the credit card processor.
And in the lower case it's going to be the PayPal processor that does the thing.
Okay.
So the explanation of what was going on is longer than the actual writing of the code.
But that is fine because this is really important.
And this is also something that took me a while to understand because it's very abstract and it's quite
advanced coding already.
Right?
Okay.
So that's it for this video.
See you in the next video.