1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

What is a Factory Method??

Discussion in 'Programming' started by pradeep, Nov 21, 2006.

  1. pradeep

    pradeep Team Leader

    Joined:
    Apr 4, 2005
    Messages:
    1,646
    Likes Received:
    86
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Kolkata, India
    Home Page:
    What is a Factory Method??
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,292
    Likes Received:
    365
    Trophy Points:
    83
    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.
     
  3. pradeep

    pradeep Team Leader

    Joined:
    Apr 4, 2005
    Messages:
    1,646
    Likes Received:
    86
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Kolkata, India
    Home Page:
    OK! So does it mean that I create the object with some different paramater and without using the constructor??
     
  4. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,292
    Likes Received:
    365
    Trophy Points:
    83
    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.
     

Share This Page