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,645
    Likes Received:
    87
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Kolkata, India
    Home Page:
    http://blog.pradeep.net.in
    What is a Factory Method??
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    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,645
    Likes Received:
    87
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Kolkata, India
    Home Page:
    http://blog.pradeep.net.in
    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,375
    Likes Received:
    388
    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

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice