Questions tagged [setters]
A setter is a method used to control changes to a variable. It's most often used in object-oriented programming, in keeping with the principle of encapsulation.
27 questions
-4 votes
2 answers
340 views
What to name a method which reads and sets value without return value?
I have a method like this private void foo() { this.myValue = readSomeValueFromFileSystem() } What is the good name for that ? Is there any convention about it ? I feel that it is kinda set but ...
84 votes
12 answers
31k views
What is the utility and advantage of getters & setters especially when they are merely used to read and assign values to properties of an object? [closed]
I’m still really new to learning to program. Just learning the syntax for a few programming languages at the moment. The courses I viewed for C# and Java touched only very briefly on getters & ...
1 vote
1 answer
5k views
Calling a private method in a setter to update object at every change of the property
Code below shows setting a value of an object's property and calling a private method in a setter to update the status of the object. Is this call a good practice or setter at most should only ...
-5 votes
2 answers
268 views
What is the proper way to unspecify an integer's value in C++? [closed]
// Default initialization int i; // i has an unspecified value return i; // Probably 0, but Unreliable i = 5; // i has a specified value i = int();// This will give it a specified value, 0 i = ...
-2 votes
1 answer
438 views
Set result of getter instead of setter [closed]
Is this a legit use of getter Lady lady = new Lady(); lady.getWater() = "hot water"; if we suppose getter returns Class Lady { public String getWater() { this.water; }} ?
12 votes
5 answers
8k views
Is it a bad idea to use getters/setters and/or properties at all? [duplicate]
I am perplexed by comments under this answer: https://softwareengineering.stackexchange.com/a/358851/212639 A user is arguing there against the use of getters/setters and properties. He maintains ...
4 votes
7 answers
2k views
How exactly are getters and setters defined?
Note: Questions with similar title have been asked before, but please read the full text before claiming that this is a duplicate. Since everybody in OOP uses the terms getter and setter, I would ...
0 votes
2 answers
3k views
Should the getters and setters of a stl container access the container itself or the elements inside it?
Consider I have a vector and map as class members: class MyClass{ protected: std::vector<int> myVector; std::map<int,std::string> myMap; }; Should the getter and setter access the ...