Questions tagged as 'getters-setters'

3
answers

How to avoid the use of setters in such cases?

In general object orientation it is advisable to avoid the use of setters. The usual justification for this is that logic that modifies the state of an object must be encapsulated in the object. Therefore, the ideal is the object to expose behav...
asked by 28.07.2016 / 05:43
2
answers

How to customize the getter in Kotlin?

When we create a variable of type val , in the case of Java, only getter is created in relation to it. Different when a variable of type var is created, in which getter and setter is created. Here is an example:...
asked by 10.08.2017 / 15:43
5
answers

What is the difference between referencing an attribute directly or by get / set

As an example I have a private String atributo , so I can have two ways to reference it, internally in the class: this.atributo And also: this.getAtributo(); Is it correct to say that it is wrong to use this.atributo and s...
asked by 19.05.2016 / 04:14
1
answer

Understanding the pythonic way of dealing with properties

I'm trying to figure out how this python properties issue works. But the problem is that in all the net tutorials out there I only find the damn example with only one attribute. I'm looking for an example where you have more to do with day to da...
asked by 01.07.2015 / 01:56
1
answer

When to use magic method __contructor or set and get

My question is regarding builder, for example, I have a class with name, age. the correct one is to use __constructor to pass values to them or use set and get?     
asked by 28.12.2014 / 04:10
2
answers

How to transform attributes into properties?

In C #, I can avoid using getter and setter , turning the attributes into properties, as below: public class Pessoa { public int pes_idade { get; set; } public string pes_nome { get; set; } } Can you do this in Java?  ...
asked by 26.08.2016 / 20:36
4
answers

Use of setters in the constructor

I would like to know if there are any semantically speaking differences between these two constructors: public Aluno(String n, float n1, float n2) { this.nome = n; this.setNota1(n1); this.setNota2(n2); } and public Aluno(String n...
asked by 02.11.2015 / 03:20
3
answers

In structures (struct) is it necessary to use getters and setters or only in classes (class)?

Is it necessary to use setters and getters in structures to maintain good practices or is it only necessary in classes?     
asked by 13.12.2017 / 23:28
2
answers

How to set a private property in Python? Is there protected property?

I come from PHP. In it, when we want to define a property of a class as private we add the keyword private in its declaration. Example: class StackOverflow extends StackExchange { private $language = 'en'; // privado, só pode ser...
asked by 04.03.2015 / 20:56
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