There is at least one example of a proxy that you're probably using every day already and that is the
smart pointer classes inside C++.
So let me give you an explanation as to why a smart pointer would be a proxy.
Well here I have an interface called bank account and I have current account which implements this interface.
Now if I decide to work with rural pointers what I can do is I can make an instance of such an account
and I can manipulate it using the dash greater than operator.
So fairly obvious stuff.
So essentially what I can do is I can make a bank account what's called bank accounts pointer a for
example I can the can you current account with a certain balance starting balance.
And then I can call let's say the deposit function to deposit even more money on the account and then
I can delete the account.
So when you use a smart pointer instead what you're essentially getting is you're getting something
which behaves for the most part just like a pointer.
What I mean is if you say Auto V to be equals make shared current account 123 you're getting a pointer
which behaves just like an ordinary pointer in so far as you can get for example the bank account so
you can certainly call the deposit function directly or you can get a pointer to.
Let's say if you want a pointer to the bank account from a current account you could save bank account
pointer actual equals beat out.
So this is an enhancement.
This is something that the proxy gives you over the API that you have.
So you have your typical API.
I mean if you look at B dash great then obviously you're not just dispatching an ordinary pointer there
is a Aro operator defined on the Sharepoint or unique pointer and that's how you get to the underlying
object.
But there is additional API some time so here you get an enhancement for example you can get the correct
pointer and then you can call something on the pointer or indeed on the original object so I can call
actual deposit or I can Coleby downgrade to then deposit.
So in this case what's happening is we have this pointer which acts as if it were an ordinary pointer.
So for example if I had code similar to like an IF statement which checked for an ordinary pointer array
then an if statement on the smart pointer is equally valid because it also defines conversions to boolean.
So in this case we have kind of equivalence and this is perhaps the best way of illustrating the proxy
so a proxy is essentially an object which looks and behaves as if it were in fact a current account.
In this case so B is a pointer to a current account but it is a smart pointer.
So in addition to providing some of the underlying functionality that you will get with a raw pointer
it also provides additional benefits.
For example I don't have to call delete on it and I don't have to.
I don't have to have any problems when I'm passing this pointer around in my applications code.
So this is the simplest example of a proxy and it's a proxy that works reasonably well so a proxy doesn't
have to just replicate the API Exactly and that's it.
You also get additional benefits like for example being able to get the underlying pointer and then
assign it to a roll pointer value.
So in this case the proxy is a bit more flexible than just a replication and also provides additional
services as well.