What is a Factory Method??

pradeep's Avatar, Join Date: Apr 2005
Team Leader
What is a Factory Method??
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
In Factory methods you normally have methods to create objects something like CreateXXXX taking the string as the parameter.

It creates objects of type derived classes which is hidden and you have base class which exposes all the methods and operation a derived class can handle.

As an example
Class Fruit has lots of methods like Cut, Mix and you have some general function like CreateFruit which takes a string and create an object of type of derived classes and return you the object and you can operate on the object without knowing the details of the object but you know some general things from Fruit.
0
pradeep's Avatar, Join Date: Apr 2005
Team Leader
OK! So does it mean that I create the object with some different paramater and without using the constructor??
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Nope. You as a user of such a method does not need to create the objects of subtype identifying them but you just need to know the string. Constructor is actually called but that is done by CreateXXXX method.