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/delegation or aggregation because, LocalDate is immutable, and thus adding an instance variable to the LocalDate object would break the immutability
Question: What design technique is applied? is it just the weakest dependency? or also a delegation? or something else?
Aucun commentaire:
Enregistrer un commentaire