Skip to main content

Questions tagged [getters]

4 votes
2 answers
2k views

I've read somewhere about a pattern that is as follows: if it'll change the state of the instance, the method should be named with a verb and return void; and if the method just returns something (...
Bernardo Benini Fantin's user avatar
15 votes
9 answers
6k views

Note: I'm not looking for opinions on whether the authors of the article below are right or wrong. Mainly I'm looking for the exact definition of what they mean by getters, especially since I know ...
Ced's user avatar
  • 609
2 votes
1 answer
451 views

Might be a silly question or something I might have just messed up in my head but here we go... I saw a code example of someone using getPos() in their own class to retrieve the current position of an ...
darclander's user avatar
2 votes
4 answers
2k views

I've seen this problem in a few different contexts now but I'm not sure what it's called or how to think about it. Suppose I have a service, AccountService, that serves accounts from a database, e.g. ...
Andrew Cheong's user avatar
-2 votes
2 answers
769 views

Everywhere is said that a private member can only be accessed from inside the same class, but at the same time, we can access the private member using getters and setters, therefore my question is: ...
Ian Mozz's user avatar
2 votes
4 answers
1k views

Suppose I have a Attendance class public class Attendance { private PersonInfo personInfo; public PersonInfo getPersonInfo() { return personInfo; } } And I want to check if person is ...
user3153970'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
2 votes
2 answers
429 views

Consider the following JavaScript code: class MyClass { #myPrivateField; constructor() { #myPrivateField = new AnotherClass(); this.theGetter.method1(); // or: this.#myPrivateField....
goodUser's user avatar
  • 129
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
3 votes
4 answers
2k views

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 So ...
The Once-ler's user avatar
2 votes
1 answer
712 views

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 ...
The Once-ler's user avatar
0 votes
1 answer
599 views

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 ...
Tlaloc-ES's user avatar
  • 387
4 votes
1 answer
244 views

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: ...
user avatar
0 votes
0 answers
2k views

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(){...
WendyG's user avatar
  • 133

15 30 50 per page