There is really no true good style; it depends on the context and on your needs.
Using:
String salary = company.getPerson(id).getData().getSalary(); String postcode = company.getPerson(id).getData().getPostCode();
If you need to improve your memory usage .
Simple use:
Data data = company.getPerson(id).getData(); String salary = data.getSalary(); String postcode = data.getPostCode();
If you want to increase productivity .
For readability, this is too subjective for me. There is both readable honestly.
The second example has the benefits of refracting company.getPerson(id) , and the variable also allows you to perform some validation without calling company.getPerson(id) again. I often prefer this style, but, again, depending on needs, the first solution might be better if getPersonne(id) and getData() cannot return null.
source share