vendredi 17 juillet 2020

Design/over re-factoring: Should I just have getters for only properties, or include getters for the underlying object as well?

I feel as if I am suffering from a case of thinking too hard and over-refactoring. Currently in my application, most fields of my objects are some property type. I have a getter for the property itself and the underlying data structure. A simple example is as follows:

private SimpleStringProperty s;
public String getS(){ return s.get() }
public SimpleStringProperty getSProperty(){ return s }

VS:

 private SimpleStringProperty s;
 public SimpleStringProperty getSProperty(){ return s }

I am wondering if method 1 or 2 is more 'proper'. I feel that method 1 is convenient, for if I ever just want the string value, I can call obj.getS(). However, it also feels kind of redundant to have that method, because I could also just do obj.getSProperty().get() using method 2. However, for method 1, I could also format the string in the getter if I wish, such as concatenating with a dollar sign for example...

I think I am just over thinking this and it doesn't really matter. But if there is a 'standard' way that people follow, I would like to know. I just want the cleanest/most readable code possible

Aucun commentaire:

Enregistrer un commentaire