In the java.time.LocalDate
of Core Java 8, the format
method is implemented as the following:
@Override // override for Javadoc and performance
public String format(DateTimeFormatter formatter) {
Objects.requireNonNull(formatter, "formatter");
return formatter.format(this);
}
Similarly, the static parse
method is implemented as the following:
public static LocalDate parse(CharSequence text, DateTimeFormatter formatter) {
Objects.requireNonNull(formatter, "formatter");
return formatter.parse(text, LocalDate::from);
}
This is different from composition or aggregation because, LocalDate
is immutable, and thus adding an instance variable to the LocalDate
object would break the immutability. From the aspect of responsibility, it doesn't seem to be delegation, either, according to the book Refactoring: Improving the Design of Existing Code, where the delegation also requires a corresponding instance variable
Question: What design technique or pattern is applied? is it just the weakest dependency? or also a delegation? or something else?