In core Java 8's date and time library, i.e. the classes inside package java.time, I found a special common trait: there is no public constructor on each class of this package, and thus all classes can be instantiated only through some static methods such as of, now etc. In this sense, the classes inside java.time resembles the factory design pattern. However, these classes do differ from factory design pattern in that the essence of factory design pattern is to loose couple the code to instantiate various types of objects with a common method and, the type of the returned object instance is determined until runtime.
However, esp. in the class java.time.LocalDate and java.time.ZonedDateTime, the keyword factory was indeeded mentioned. One can find the keyword factory from:
So I would like to know did java.time.LocalDate and java.time.ZonedDateTime apply the factory design pattern at all?
Aucun commentaire:
Enregistrer un commentaire