Answered by:
different implementations of the factory method pattern...

Question
-
User395669356 posted
hello
i have been facing two different implementaions of the factory method pattern. i was hoping someone helps me to understand which one should i use. here is the implementation in dofactory.com:
http://www.dofactory.com/Patterns/PatternFactory.aspx
and here is the other one in codeproject.com:
http://www.codeproject.com/KB/aspnet/SoftArchInter1.aspx#Whataredesignpatterns
i think the pattern that is explained in the codeproject.com is very straight forward while the pattern that explained by dofactory is not that straight and looks like a little like abstract factory pattern instead of factory method. so which one is a better implementaion ??Friday, June 3, 2011 12:11 PM
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:
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.
Saturday, June 11, 2011 7:38 AM