I have two coding styles:
public class Age
{
public double AgeYear { get;}
public double AgeInDays {get;}
public Person GetAge()
{
int x;
//implementation that calculates AgeYear and AgeInDays
return this;
}
}
Age a = new Age();
Age a1 = a.GetAge();
Second implementation:
public class Age
{
public double Age { get; set; }
public double AgeInDays { get;set; }
public void CalculateAge()
{
int x;
//implementation that calculates Age and AgeInDays
Age = x;
AgeInDays = Age * 365;
}
}
Age a = new Age();
a.CalculateAge();
double age = a.Age;
double ageInDays = a.AgeInDays;
This is just a simple example. What do you prefer - change object properties in void method and then expose public properties or call some method that returns object itself.
a
anda1
refer to the same object?