As you probably know other programming languages such as C-Sharp have this idea of properties now there
probably is nothing more than a field plus a getter and the Center for that field.
So let's suppose that we wanted to get properties in C++.
Now apart from using something sophisticated like metaclasses which aren't part of C++.
Well you could do is you could construct a simple template class to act as if it were a property.
So let me show you how this would work.
So essentially here is the idea let's suppose you have a computer game and you have a creature in that
game.
So you as a creature and typically you give the creature certain statistics like strength or agility
so you might do it.
So you might say in strength Nissho value of 10 and maybe agility or something like that.
So you would create a creature and you would say See dog strength that equals 15.
For example if you wanted to modify it.
So this is just manipulation of an ordinary feel.
Now let's suppose that for some reason you actually wanted to intercept the assignments as well as the
access to this field so you want something which is effectively a property so you want the getters and
setters but you don't want to just go ahead and generate them because if you were to generate let's
say the getters and setters for whatever fields you you would no need to call those things differently
so if you wanted to change the strength you would call set strength.
And similarly for the other fields as well.
So instead of doing this what you can do is you can build a prop of the proxy that you can subsequently
customize to give you certain behaviors which you actually need.
So a property proxy would be a template class so you would have template type name T.
And let's call it property.
There would go so probably proxy keeps a value of some kind.
And this is a value of type T you would also have an initializer like a constructor.
Here for example.
But the initialization can actually be done differently so instead of having the value you just written
to the appropriate field you would actually use assignment.
Now what does it mean to assign a property value.
It means implementing operator equals.
So you have operator equals which by the way returns an instance of tea and I'm talking mainly about
the value semantics here.
If you want to start doing some sort of reference semantics that's up to you I'm just imagining a property
as a wrapper for an integer or an as to the String for example something to that effect.
So here we would have operator equals which takes a new value.
And here you would return value equals value.
So you would both assign the value and you would return the result.
So here in the constructor what you would do is you would say Star this equals value.
And that way you would actually call the operator equals.
So this is where assignment happens.
So for example here you can for example wattled sidedly assignment something to that effect let's put
the line break in here.
And similarly if you were to get the value of the way you would do this is by implementing the operator
which actually converts whatever you're trying to get to the type T.
So you would have operator T like so where you would return the value but you could also have some sort
of get member function if you wanted that as well.
So no you would go into Cretien you would modify the creature to implement the traits strengthen the
choti using probably So you would have a property off type end called strength once again with a value
of 10 and you can duplicate this and have agility with a value of five for example.
So nothing really changes for creature in the sense that used to right see that strength for example
equals 11 and then you can also say Auto X equals CDATA agility.
Although you probably want to avoid order and just use into something like that.
So you know that the conversion operator actually kicks in.
So this is how you build a property proxy and we can actually run this and we get to see some of the
output from the assignment for example so here we have assignment and we've added additional behaviors
to assignments Similarly you can have additional behaviors to whatever Geter implementations you actually
have.
And that way you get some diagnostic city but really the implementation of property is up to you you
have to decide what you want to put into it.
So here we go we have a number of assignments here.
I've executed this as a test rather than an ordinary demo it doesn't really matter for our purposes.
We can certainly run it so we have assignment assignments assignment and the reason for that is that
well first of all we have initialization of the creature we assign strength and also there are other
assignments happening behind the scenes here as we're kind of copying things and whatnot so this is
how you implement a properly proxy.
And this is something that you can sort of stick in place of an ordinary field and have it operate in
pretty much the same way.