What is difference between abstract factory and factory method design pattern? [Resolved]

Posted by Rajeshatkiit under C# on 12/17/2015 | Points: 10 | Views : 540 | Status : [Member] | Replies : 8
What is difference between abstract factory and factory method design pattern?




Responses

Posted by: Rajnilari2015 on: 12/19/2015 [Member] [Microsoft_MVP] [MVP] Platinum | Points: 50

Up
1
Down

Resolved
@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

Factory Pattern (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
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.



Regards

Niladri Biswas
(RNA Team)

--
Thanks & Regards,
RNA Team

Rajeshatkiit, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Raja on: 12/19/2015 [Member] Starter | Points: 25

Up
1
Down
Thanks a ton @Rajnilari2015 for your great responses. It is helping all of us in big ways.

@Manideepgoud, I do not think @Raj.... has copy-pasted the code in this thread. I think you should see what he is doing and then write your response. Just a suggestions otherwise it doesn't make sense!

Thanks,

Regards,
Raja, USA

Rajeshatkiit, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rajnilari2015 on: 12/17/2015 [Member] [Microsoft_MVP] [MVP] Platinum | Points: 25

Up
0
Down
Please refer the link for a similar kind of discussion http://stackoverflow.com/questions/5739611/differences-between-abstract-factory-pattern-and-factory-method . Please let us know if you have any doubt in understanding.

Thanks in advance.

--
Thanks & Regards,
RNA Team

Rajeshatkiit, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rajeshatkiit on: 12/18/2015 [Member] Starter | Points: 25

Up
0
Down
Thanks.



Rajeshatkiit, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rajeshatkiit on: 12/19/2015 [Member] Starter | Points: 25

Up
0
Down
Plz explain in detail instead of posting url.

Rajeshatkiit, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Manideepgoud on: 12/21/2015 [Member] Starter | Points: 25

Up
0
Down
Sorry Rajnilari,
It was link not code, Later i realized that the link you have submitted was right.

Rajeshatkiit, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rajnilari2015 on: 12/21/2015 [Member] [Microsoft_MVP] [MVP] Platinum | Points: 25

Up
0
Down
@Manideepgoud Sir, No problem Sir. (:

--
Thanks & Regards,
RNA Team

Rajeshatkiit, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Manideepgoud on: 12/19/2015 [Member] Starter | Points: 25

Up
-1
Down
Do Not copy paste the code. please provide the code snippet and describe it in detail so that it would be easy for the post author to understand the subject and implement it.

Thanks.

Rajeshatkiit, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response