A lot of the publicly available Java APIs seem to use getInstance in order to generate and return an object. I’m curious about why this is so — why not just use default/parameterized constructors instead?
Is there an associated design pattern?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It is associated with Singleton Pattern.
Many times there are also Factory Methods which help you in creating objects.
For example:
Boolean.parseBoolean("true");Advantages of Factory Methods are they are more verbose and easy to grasp than a series of constructors.