As a general rule, should the parameter be as primitive as possible? And thus have the conversions to whatever data format/class we need be done inside the method?
eg. insert a String and then have the conversion to LocalDate be done inside the - in this case, setter - method?
// inside a class that has a date field
private LocalDate date;
public void setDate(String stringDate) {
LocalDate date = LocalDate.parse(stringDate);
this.date = date;
}
or have this conversion be done outside of the class?
// inside a class that has a date field
...
private LocalDate date
public void setDate(LocalDate date) {
this.date = date;
}
...
// in TextUI class
...
String stringDate = scanner.nextLine();
LocalDate date = LocalDate.parse(stringDate);
*object*.setDate(date);
...
I am not seeking for an answer to this particular situation, but rather for a general rule. (Thus also not necessarily for setters methods only, but for any method)
On the one hand, to obtain max abstraction, I think the second example is the way to go. On the other hand though, the first example feels more as though the object takes care of its own data integrity.