Design patterns·Making things
the class has private constructors and a set of named methods that build it, so the call site says what kind you wanted.
Static factory method
Also callednamed constructor, of() method, creation method
A static method on a class that returns an instance of it, in place of a public constructor. It buys three things a constructor cannot: a name, so two constructions with the same parameter types are distinguishable; freedom to return a cached or subclass instance; and a place to validate before anything exists. The cost is that a class with no public constructor cannot be subclassed conventionally, which is often the intent anyway.