Skip to main content

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.

-4 votes
2 answers
342 views

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 ...
gstackoverflow's user avatar
2 votes
3 answers
282 views

Why learning about Fluent Interfaces, I came across this post which states that using set hints one is mutating the object whereas with is returing a new object. I have seen this pattern first hand ...
Ezequiel Castaño's user avatar
84 votes
12 answers
31k views

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 & ...
ProjectDiversion's user avatar
4 votes
4 answers
4k views

I doubted to post this question to the general StackOverflow, but it is suggested to not post opinion-based questions and this might be one. And ofcourse, this is the software engineering department. ...
Jannick Breunis's user avatar
1 vote
1 answer
5k views

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 ...
apex39's user avatar
  • 121
9 votes
4 answers
1k views

I was reading this page, about when getters/setters are justified, and the OP gave the following code sample: class Fridge { int cheese; void set_cheese(int _cheese) { cheese = _cheese; } ...
QueenSvetlana's user avatar
-5 votes
2 answers
268 views

// 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 = ...
Anon's user avatar
  • 3,649
-1 votes
3 answers
451 views

My question is how I can achieve more encapsulation in TypeScript. I have a class Item, with a public setter isOwned, but I only want to call this method in specific situations: if the item is picked ...
chharvey's user avatar
  • 264
-2 votes
1 answer
438 views

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; }} ?
ZHU's user avatar
  • 129
1 vote
3 answers
17k views

For example, given the following class: public class SomeClass { //... private IEnumerable<SomeType> myEnumerable; public IEnumerable<SomeType> MyEnumerable { ...
Maciej Stachowski's user avatar
12 votes
5 answers
8k views

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 ...
gaazkam's user avatar
  • 4,529
7 votes
4 answers
686 views

This site and SO contain many pages about getters/setters and if they break encapsulation or enforce it. My question is for those developers that agree that getters/setters break encapsulation and ...
user avatar
4 votes
7 answers
2k views

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 ...
Frank Puffer's user avatar
  • 6,459
2 votes
2 answers
6k views

I'm using a repository pattern design and I've hit a stumbling block when writing a unit test for one of my methods. I'm fairly new to writing unit tests, so I would appreciate any help! Let's say I ...
Dan Johnson's user avatar
0 votes
2 answers
3k views

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 ...
ggrr's user avatar
  • 5,893

15 30 50 per page