English setter

Hi;

Setters and getters.

I'm really not understanding the concept of this.

So I have been told always remember for every setter you need a getter but no concept of why.

Any clarity please and thanks
You may need getters to access parts of your object's value: for example, std::vector and std::string have the getter size(), which returns the current size of the vector/string.

You don't need setters.

You may need modifiers ("mutators"), if something in your object can change during its lifetime. For example, std::vector has resize(), which performs a lot of things, one of which is that the value obtained from size() is changed.
Last edited on
So let me ask this what is a setters job and what is a getters job. Why does my teacher insist that those 2 things go together?

Thanks for your reply
If the teacher has something to say, you have to learn that to show that you've been paying attention. Ask him questions if you have them -- and this is certainly a valid question that shows that you're thinking and not just memorizing.

Responding with what some engineer told you on the internet, even if it's closer to what's happening in the real world, would reflect poorly.
Classes have protected and private members. Getters and setters are used to have some kind of access to that data
Topic archived. No new replies allowed.