What's the convention for calculating a class attribute in Java?
For example, doing the calculation directly in the constructor:
public class Person {
public Person(int birthyear){
this.birthyear = birthyear;
this.age = 2020 - birthyear;
}
}
compared to calling a method that does the calculation:
public class Person {
public Person(int birthyear){
this.birthyear = birthyear;
this.age = calculateAge(birthyear);
}
}
Where the calculation is complex (not like here), I'm inclined to go with the second example, but would like to follow conventions, where possible.
This may be a duplicate, in which case please point me in the right direction (couldn't find it from my searching).