Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I use "get"-prefix in my method name?

I have this abstract class that is used as data repository.

public abstract class AbstractDataSource {
    public abstract DataRow getDataRow(Key key); //or just dataRow(Key key)???
}

public class CSVDataSource extends AbstractDataSource {
    @Override
    public DataRow getDataRow(Key key) { //or just dataRow(Key key)??
        //fetch row from file and return dataRow
        //....
        return dataRow;
    }
}

More specific classes (i.e. subclasses of this class) implement methods for different data source, e.g. CSV, ARFF and other formats.

I was wondering if the "get"-Keyword is appropriate here, as the data retrieval is not just returning a variable, but could also require filesystem access or whatsoever.

So should I use the "get"-prefix or not?

Thanks

like image 929
Simon Avatar asked Feb 02 '23 10:02

Simon


1 Answers

I agree that using the get keyword can sometimes seem non-intuitive when there's real logic behind. In your case lookup or find prefixes could be good substitues. There's also retrieve as suggested by @Thomas.

This question might seem off topic at first. But naming is, at least to me, an integral part of good application design.

like image 102
Johan Sjöberg Avatar answered Feb 12 '23 08:02

Johan Sjöberg