This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Rajdeep Biswas wrote:Where and how to use those methods correctly? Why not constructors?
Other than Koen's link, Effective Java also has a very good section on using factories.
Just a few reasons for using factories are:
1. The method has a meaningful name.
2. A factory doesn't necessarily have to return you a new object.
3. A factory doesn't even have to return you an object of the specified type. It can, for example, return you an anonymous subclass (sometimes very useful).
Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here