locked
different implementations of the factory method pattern... RRS feed

Answers

  • User1682618242 posted

    or the only true implementation is the Gof implementation in dofactory ??

    The Gof implementation is the true one as they described it first. So go for the DoFactory implementation (they have nice code examples also).

    As for  the other one I'm sorry but that seems a wrong implementation. The concrete creator should create only one type of product not all depeding on a paramter passed in the Factory method

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, June 4, 2011 11:39 AM

All replies

  • User1682618242 posted

    The one from dofactory is the same "implementation" as the GoF implementation. The one from codeproject....well is an explanation.

    When in doubt go to the bible:

    http://www.amazon.com/Design-Patterns-Elements-Reusable-Object-Oriented/dp/0201633612/ref=sr_1_1?ie=UTF8&qid=1307189163&sr=8-1

    Saturday, June 4, 2011 8:06 AM
  • User877341716 posted

    More simplified way of Factory method pattern is the Convert.ToString(""), Convert.ToInt(""), etc... methods.

    Saturday, June 4, 2011 8:16 AM
  • User395669356 posted

    well, someone told me that both of those patterns are factory method. so are they ? or the only true implementation is the Gof implementation in dofactory ??

    More simplified way of Factory method pattern is the Convert.ToString(""), Convert.ToInt(""), etc... methods.

    can you explain to me how these methods are related to factory method?? because it seems to me that Convert is just a static class with static methods ??

    Saturday, June 4, 2011 11:19 AM
  • User1682618242 posted

    or the only true implementation is the Gof implementation in dofactory ??

    The Gof implementation is the true one as they described it first. So go for the DoFactory implementation (they have nice code examples also).

    As for  the other one I'm sorry but that seems a wrong implementation. The concrete creator should create only one type of product not all depeding on a paramter passed in the Factory method

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, June 4, 2011 11:39 AM
  • User395669356 posted

    i'm very interested to know why Convert and the static methods is considered a simplified version of the factory method according to sudeep_13 ??

    Saturday, June 4, 2011 1:08 PM
  • User877341716 posted

    i'm very interested to know why Convert and the static methods is considered a simplified version of the factory method according to sudeep_13 ??

     

    Though Convert class has static methods,  you need to look at the way these methods are implemented

    Convert.ToString will return a String object whereas Convert.ToDecimal would give a decimal. Similarly Convert.ToDouble will return a double.

    So a client requested object type is returned from these static methods which is the same as Factory Method.

    Let me know if you need more clarification

    Saturday, June 4, 2011 1:19 PM
  • User395669356 posted

    what i don't get is this:

    if i have to pass parameter to the factory method directly from client app then i'm not really hiding the implementation of the object that is returned by the factory. the result is that if i change the underlying object creation then i have to change the parameter which means changing the client and that is against factory pattern. as you can see in the dofactory.com example it doesn't pass any parameter to the factories. so how does it work??

    Sunday, June 5, 2011 3:25 AM
  • User1682618242 posted

    I don't see how the Convert.ToABC() is a version of the Factory Method. I expect to work with an abstrct Product and each ConcreateCreator to give me an ConcreteProduct.

    Monday, June 6, 2011 1:31 AM
  • User877341716 posted

    Hi,

     

    Please refer to the third para of Factory Pattern refresher section in the below link.

    http://msdn.microsoft.com/en-us/magazine/cc163739.aspx

    Saturday, June 11, 2011 7:38 AM