In core Java 8's date and time library, i.e. those classes in the package java.time
, I found a special common trait: there is no public constructor in 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 (usually static
), and thus 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 mentioned. One can find the keyword factory from:
- https://docs.oracle.com/javase/8/docs/api/java/time/LocalDate.html
- https://docs.oracle.com/javase/8/docs/api/java/time/ZonedDateTime.html
So I would like to know did java.time.LocalDate
and java.time.ZonedDateTime
apply the factory design pattern at all? If not, what design pattern did they apply?