Talk:Factory method pattern
From Wikipedia, the free encyclopedia
Contents |
[edit] Article doesn't really describe the GoF pattern?
In my understanding, the GoF Factory Method pattern is much more specific than the description in the article. It is like a specialization of the Template Method pattern - the methods defined in the subclasses are actually called in the base class and not part of the public interface.
Most of the article seems to be describing something more along the ways of the Abstract Factory pattern, a specialization of the Strategy pattern, where the methods defined are meant to be called by clients outside the class hierarchy.
The "Descriptive Names" example, on the other hand, seems to describe neither Factory Method, nor Abstract Factory, as both those patterns rely heavily on polymorphism. They are more of what Joshua Kerievsky calls "Creation Methods" in his book "Refactoring to Patterns".
Most of the examples u have shown is in c++,java , currently i am working on .net platform, can you put some examples in .net , so i will have more clear view!
[edit] Games comment
I don't think the extra paragraph on games in 'Comon Usage' adds anything to the article at least not in it's current form, so I've commented it out...
[edit] ImageReaderFactory::ImageReader returns pointer not value
ImageReaderFactory::ImageReader is declared to return a value (object of class ImageReader) but actually returns a pointer.
ups.. my fault. seems it's supposed to be Java.
[edit] is this c++ ?
- if it is then code should be more c++ like, otherwise you should state that this is a java piece of code,
consider the following code :
class Complex { public: static Complex fromCartesian(double real, double imag) {
return new Complex(real, imag); }
static Complex fromPolar(double rho, double theta) {
return new Complex(rho * cos(theta), rho * sin(theta)); }
private: Complex(double a, double b) {
//... }
};
Complex c = Complex::fromPolar(1, pi); // Same as fromCartesian(-1, 0)