Originally Posted by
aghast
Correct.
A factory method is a method that is called to build an instance of a class (or subclass). For this reason, you don't usually call factory methods using a class instance. Rather, you make the factory method a static method and call against the class directly.
Code:
new_instance = instance.factory(args); // NO!
new_instance = Class::factory(args); // YES!
To be fair, you could have a factory that creates objects from an instance. Suppose you want to create objects with the same complex set of arguments; you could have an instance that contains the arguments, and then you just have to ask that instance to create a new object for those arguments. For example:
Code:
MyFactory* f = new MyFactory();
// set a bunch of arguments
f
.setFoo(foo)
.setBar(bar)
.setBuzz(buzz);
MyObject* obj = f.newObject();