Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [getters]

The tag has no usage guidance.

3
votes
4answers
892 views

Should a class provide public mutators for all its private fields?

I work on refactoring an Java application based on a CAST audit. One of the criterion says that To respect OO encapsulation concepts, private fields should always be accessed through accessors ...
1
vote
1answer
106 views

Should I use accessors or public static fields for global constants?

I have to work on some code that was CAST-audited. The report says that it is bad in Java to use public static and that accessors should be preferred. That is also what I was taught at school. The ...
1
vote
1answer
143 views

use always get and set methods is a bad practique, is call directly an attribute class a bad practique in OOP?

I have a doubt about if there are some recommendations for call directly an attribute in a class I think that in OOP you always should call an attribute by the get method. For example: On set ...
4
votes
1answer
200 views

Is using getters to exchange information between objects acceptable?

Suppose I have the following Character, Potion, and PotionType classes: class Player: def __init__(self, name: str, health: int, mana: int): self._name = name self._attributes: ...
0
votes
0answers
75 views

Are groovy automatic getters and setter effectively any different to public variables?

To provide a very blunt example (as I am at work and can't currently think of a sensible example). If I write a groovy class like this class Wendy{ byte[] frank String doSomethingWithFrank(){...
-2
votes
1answer
265 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; }} ?
2
votes
2answers
210 views

OOP in Java - What can getters be used for?

Usually, getters always return the value of a variable. I learned in my literature that access to fields is controlled by getters and setters. When I had my code rated by programmers, it was suddenly ...
2
votes
2answers
335 views

Is there any reason to avoid private getters?

Even though I could write something like this (In C#. There are, of course, equivalents in other languages): public int SomeNumber { private get; set; } I have never encountered something like this. ...
12
votes
5answers
4k 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 ...
3
votes
2answers
573 views

Dealing with a lot of getters and setters

I've already asked "Dealing with a large interface". I have a further question regarding that situation. It was pointed out to me that I used a lot of getters and setters and so I broke encapsulation....
7
votes
4answers
436 views

Encapsulation and Displaying Information

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 ...
4
votes
4answers
717 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 ...
1
vote
2answers
223 views

Conflict in getter and setter method names in ruby api design

I am inheriting an api decision in an SDK I am writing where I am required to fetch domain objects (entries) from the server like this: blogEntries = client.content_type('blog').entries As you can ...
0
votes
2answers
1k 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 ...