In this video, Reynald guides you in the process of coding what’s left and required on the client side to execute the program. He then demonstrates the finished code by running it and providing a summary of the results. The intent of this exercise is to provide you a chance think through and see how all the pieces come together for the Proxy pattern.
- So we are now ready to code the client to demonstrate the Proxy Pattern. So let's go to our Main method. And the first thing that we're going to do is to Create our math proxy. So we'll do this by instantiating a new instance of this proxy that we call CalculateProxy. And the next step is to do some math.
So, just to be neat, I'll write out to the console that we are spitting out some calculations. Throw in a little neat divider there. And for the first one ...
Why don't we go ahead and do addition on a new line? And we will add ten plus five equals. And we will use our proxy to add. And this is the method that we created. We don't need to see anything else beyond that. We'll pass in our doubles.
The values of ten and five. Beautiful. I'll copy this line and then paste, paste, paste. And modify them. So that, we can have some different calculations. We'll subtract five. Then multiply by five. And then, divide by five.
Subtract Modify our third proxy with multiplication. And then our last with division. That's it! Then we'll wait for the user by pausing the screen. So again, we're providing functionality through our proxy.
And all the implementation details regarding how that functionality is done is not known to the client. I'll go ahead and run by hitting the bug button. And there's our calculations and results. So, all in all, this pattern provides the local proxy class to give specific functionality of some class without sharing implementation details to the client. And the proxy also dictates how the client will access the functionality.
So consider this pattern whenever you want to give a client access to functionality without sharing details.
- Why use design patterns?
- Prototype pattern
- Bridge pattern
- Façade pattern
- Flyweight pattern
- Proxy pattern
- Memento pattern
- State pattern
- Strategy pattern
- Template Method pattern