I was reading factory method pattern from wikipedia link.
There are some limitations mentioned three limitations mentioned there.
These are all fine. But there is a conclusion statement written, which I am not able to get.
"All three problems can be alleviated by making factories first-class class members rather than using the design pattern"
Limitations mentioned there are as follows.
1*The first limitation is that refactoring an existing class to use factories breaks existing clients. For example, if class Complex was a standard class, it might have numerous clients with code like:
Expand|Select|Wrap|Line Numbers
- Complex c = new Complex(-1, 0);
2*The second limitation is that, since the pattern relies on using a private constructor, the class cannot be extended. Any subclass must invoke the inherited constructor, but this cannot be done if that constructor is private.
3*The third limitation is that, if we do extend the class (e.g., by making the constructor protected -- this is risky but possible), the subclass must provide its own re-implementation of all factory methods with exactly the same signatures. For example, if class StrangeComplex extends Complex, then unless StrangeComplex provides its own version of all factory methods, the call StrangeComplex.fromPolar(1, pi) will yield an instance of Complex (the superclass) rather than the expected instance of the subclass.
Any assistance will be greatly appreciated.
Regards,
Sumit