Questions tagged as 'getters-setters'

4
answers

Getters and setters are an illusion of encapsulation?

It is common to teach that it is right to leave class attributes private and to create getters and setters for them, all because of encapsulation. Is not this the same thing as leaving everything public, since you can change and...
asked by 21.07.2014 / 12:57
3
answers

Why use get and set in Java?

I learned in college a while ago that I should always use getters and setters to access values in an object and I heard it is for security. p> So I ended up always using and seeing other people using, until I started programming Android and I...
asked by 14.11.2014 / 05:55
4
answers

Getters and Setters are obligatory or facilitators?

Lately I have read some Java books, but there is a part that makes me confused in this kind of accessor methods - gettters and setters. The question is: I'm forced to write in this type of methods, for example, getName () or just have to w...
asked by 24.09.2014 / 15:49
2
answers

Getters and Setters can only "walk" together?

I am studying object orientation and am having some questions on the encapsulation part. For example: Class Url { private $url; public function setUrl($url) { if (filter_var($url, FILTER_VALIDATE_URL)) { $this -&...
asked by 21.12.2014 / 07:30
2
answers

Why should not I change the getters and setters?

Recently I came across a friend talking that it is not advisable to change getter and setter. I had made a setter change of a List . In it I did not receive a list by parameter, but an object of the type, and within the method I made a...
asked by 13.06.2016 / 19:35
2
answers

Is it really necessary to use mutator and accessor methods (setter and getter) in PHP? And the performance?

I have come to realize that most other libraries use the setters and getters methods (hereafter referred to as mutator and accessor in>), to change the ownership of some class. For example: class User { protected $name; public...
asked by 29.01.2016 / 19:36
3
answers

When to use Setters and Getters?

I'm studying OOP and in the encapsulation part I have a question about when to use getters and setters , besides being able to validate the parameter passed, what is the utility of using ? I could just "get" the given by __construct...
asked by 12.12.2014 / 07:50
3
answers

Pythonic way of defining setters and getters

Searching the internet I see that it is highly recommended not to use Setter and Getters in Python classes, however, I can not determine a way to access private values without using them. There are several recommendations on using properties, bu...
asked by 28.02.2017 / 05:32
2
answers

Equal sign in Ruby method definition

I came across the following method definitions and would like to know the difference between the first and second definitions. This first one does not have the equal sign in the definition: def nome nome_exibicao(:nome) end This s...
asked by 01.11.2017 / 20:47
3
answers

Generate setters only in the class constructor or generate outside the constructor

In Java classes, it is common for to create private attributes and to generate getters and setters for these attributes. But, I read that you can do something a little different: only generate the getters and leave the setters in the...
asked by 08.08.2014 / 15:06