9

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

Simon
  • 9,255
  • 4
  • 37
  • 54

2 Answers2

10

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.

Johan Sjöberg
  • 47,929
  • 21
  • 130
  • 148
2

Do you want to this method to be a bean getter, so you can use it with things like BeanUtils? Given that it is doing heavy I/O and some logic, probably not, so I would name it differently.

C. Ross
  • 31,137
  • 42
  • 147
  • 238