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?