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...
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:...
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...
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...
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?
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?
...
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...
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...
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...