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...
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...
A very simple question:
Given this class:
public class User {
private String nome;
//get/set
public boolean fazQualquerCoisa(){
**duvida**.equals("algumacoisa");
}
}
Within the method Does AnyCase () , should I access the n...
A few days ago, I was talking to a friend about Java, and asked what part of the subject they were studying. So he replied that they were starting their studies on inheritance.
As they were long overdue, I asked how they suddenly jumped to in...
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:...
Observer uses abstraction and interfaces . Let's suppose that a Observer "watches" the changes of state of certain classe and informs them to another external agent, we can consider this a break of encapsulation, since...
This is the concept that I have tried hard to understand, but I have never fully achieved it.
I'll take this excerpt from a Deitel book to illustrate:
It is better software engineering to define member functions outside the
class defi...
I have two models User and Post .
When editing a post , I want to know if the user is the post author (the post has a user_id authorize editing.
If I have a method inside the Post class that receives a User...
I have an .xls file that I would like to encapsulate next to the apk so that at the time of installing the app it uses that file to populate a database. How to do?
Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides , write the following statement:
"... inheritance violates the encapsulation."
Below is the paragraph that contains this statement:
" ... class inheritance also has some...