Can anyone help me on how to create Static factory Methods?
I know that Calendar and DateFormat class from Java API use Static Factory implementation.
But I am not really sure how implementation should go as I have read that Static Factory implementation avoids creation of objects multiple times.
How to really achieve that.
Sumukh Deshpande wrote: I have read that Static Factory implementation avoids creation of objects multiple times.
Not really!. actually it depends how you implement the static factory method. singleton class uses this pattern.
example:
this method produce only one instance
I like to use factory methods for value classes. If I have an immutable value class, I provide a factory method and make the constructor private. Most of the time, the factory method will simply call the constructor, but it gives me the freedom to return cached values to the user in the future.
Creativity is allowing yourself to make mistakes; art is knowing which ones to keep. Keep this tiny ad:
Gift giving made easy with the permaculture playing cards