Help understanding "get" and "set"
i used to learn c++, now that get and set is really confusing...
can it be explained in a way i understand...?
7 Replies
and how is it useful?
In C++ you might've used getter and setter functions, like
The same goes for PHP, Java, and other lesser languages
The purpose of it is encapsulation
The data itself is always private, internal to the class, to the object
The only thing that's public is the accessors of that data
It gives you full control over the mutation of the internal state of the class. You can disallow setting it if you want, you can add some logic to the getter, whatever you need
That's kinda long, tho, so in C# it's been shortened
oh
$getsetdevolve
can be shortened to
can be shortened to
can be shortened to
can be shortened to
Here's a nice lil' breakdown
thanks for that