Shivdas Nair

Greenhorn
+ Follow
since Sep 19, 2005
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Shivdas Nair

Again , I would start by recommending the Head First Design Patterns book...I have just started reading this book and I think it gives a pretty good idea of which these two patterns.

Both patterns encapsulate object creation logic.The benefit of encapsulating object creation using the factory method is that the client programs are de-coupled from the product creation logic.Especially when the product is available in different flavours(e.g. cheese Pizza, Veggie Pizza , etc..) and these flavours can be further customized to "specific" tastes (Texan , Californian, Indian , Chinese etc. :-), you will see that the Factory method pattern gives you a neat way hide the complexity of these combinations from the client program.Also, besides encapsulating the object creation logic, the Factory method pattern also allows you to define a framework for how the object is eventually to be used and delivered to the client.Thus you will only encasulate the logic of putting together the ingredients of the pizza, while the baking , cutting and packing process will remain same across franchise's across the world...If you refer to the HFDP book , you will get a very clear idea of how this is achieved using the Factory method pattern.


Abstract Factory on the other hand allows you even more flexibity in terms of creating these different pizza's customized to local "tastes"...what if the Pizza chain wants to open a new outlet in Turkey and while allowing the pizza to be tailored to the Turkish taste , still it must enforce that the the ingredients used in Turkish Pizza should use one of the existing interfaces defined for the Dough , Sauce etc.Or for example in India, where you get Paneer Mushroom Pizza and Panner is not a known ingredient anywhere else in the world (right ? ), how will you allow your program to be flexible enough to accomodate these variations ...This mix and match is made possible by using the Abstract Factory pattern..

In Factory method pattern , you have just one factory , which deals with the product creation....In Abstract factory pattern, you have the product creation factory and one more factory to create the ingredients of the product.I remember this better as "Singly abstracted" Factory Pattern and "Doubly Abstracted" Factory Pattern :-)

I hope this was helpful....But surely , do read the chapter on Factory pattern in the HFDP book.This is explained in a much better and clever way there.

Thanks
Shiv