I have an object to read data:
DataReader dataReader = new DataReader();
And object to read:
Data data = new Data();
I can read data like so:
dataReader.read(data);
Or I can pass data
to dataReader
constructor and read it within dataReader
object.
What is more efficient?
And what is better in case read() method is implemented like this:
public void read(Data data) {
this.readString(data);
this.readString(data);
}
And method readString(Data data)
:
private void readString(Data data) {
data.nextLine();
}
Meaning, is it better to have one local data object and call its methods or pass it several times as methods argument when java passes object by value not reference? What works faster and consumes less memory?