@Rajeshatkiit Sir, we have provided the link ( http://stackoverflow.com/questions/5739611/differences-between-abstract-factory-pattern-and-factory-method
) because it has elegantly explained the same question that has been asked here. However, below is a brief explanation on the same
(Excerpt from my article : http://www.dotnetfunda.com/articles/show/1929/let-us-learn-factory-pattern
If we need the creation of many different types of objects when all derived from a common base type, Factory Pattern is the choice. Factory pattern does this by the help of Factory Method.It defines a method for creation of objects to sub classes.This means that a base class(abstract class) or interface is defined and subclasses which implement the interface / abstract class , are left to object instantiation. However, client code doesn't create an object against this interface. At run time, the Factory Method accepts a desired object as a parameter and returns a base class pointer to a new instance of that object.This pattern works best when a well-designed interface is used for the base class, so there is no need to cast the returned object.
Abstract Factory Design Pattern exposes an interface for creating families of related or dependent objects
. It does so by providing multiple factory methods
So from this, we can figure out that an Abstract Factory can be use while we need to produce multiple factories (for producing multiple items) which it does through multiple factory methods via composition whereas in case of factory pattern, the object creation happens through a single factory method for only one single item.
Another difference that we can say is that, in the case of Factory the object creation happens directly through the class instance of the factory (we can use DI but again underlying the same stuff) as opposed to the Abstract Factory where it happens through interface.
But this difference is only from the implementation prespective
Let's conclude by saying that please re-read the last two statements of the answer. That's the cardinal point between the two.
Equally, please read/re-read the link ( http://stackoverflow.com/questions/5739611/differences-between-abstract-factory-pattern-and-factory-method
) provided as there the answer has been presented with many examples.
Also it would be worth mentioning here the article ( http://www.dotnetfunda.com/articles/show/889/design-pattern-implementation-using-csharp
) provided by Mr. Abhishek Sur ( http://www.dotnetfunda.com/(S(ja4yqmapknkduwe3fi1pwm45))/interviews/personality/1383/interview-with-microsoft-mvp-client-app-dev-abhishek-sur
) which is a nice one with lot's of example which will equally help and most importantly it is available at DNF (:.
Hope this will be useful for understanding. In case of any doubt, any where, please feel free to ask us.
Thanks people for your time and suggestions/advices.
(RNA Team)Rajeshatkiit, if this helps please login to Mark As Answer. | Alert Moderator