Back to list
Views:   15.7K
Replies:  1
Archived
Difference between Factory Method and Abstract Factory
Hi,

I am not understanding the difference between Factory Method and Abstract Factory.
Can anyone please elaborate more on Abstract Factory?

Regards,
Sandeep Bhujabal
Sandeep Bhujabal, Mar 29, 2010
It's a matter of degree of similarity - the more similar the classes, the more applicable the Abstract Factory. If they are less similar, Factory Method works better.
Apr 02, 2010
For instance, ships and airplanes both have locations and movement. They may be similar enough to use a common Abstract Factory, implementing several methods such as movement, acceleration, and fuel consumption. LOTS of similarity for 2 different classes. However, ships and islands are different enough that the Factory Method may be all that they share, returning an object that defines the position on the map and perhaps a graphic to draw it on a display context.
Apr 02, 2010
The Abstract Factory would be used as the base class for classes which are used only to construct or instantiate many similar classes. The Factory Method would provide a common method for various classes which may implement that method differently, and may be very different in other ways that make using a common base class not a good way to implement classes whose only similarity is in this method which returns objects of a particular type.
Apr 02, 2010
Good evening, Sandeep. The first difference is that Abstract Factory is an abstract CLASS, which is used as a template for several classes which build similar objects, whereas Factory Method is an abstract METHOD of a larger abstract class or perhaps of an interface,
Apr 02, 2010
Reply 1
Practically speaking; both are creational pattern. You can use either of them for creating the object. I would say Abstract Factory is gaining the points when you wants to create the multiple object from the same family.

--
Kaushal Patel
http://kaushalp.blogspot.com
Kaushal Patel, Apr 14, 2010
Stay Inspired!
Join other developers and designers who have already signed up for our mailing list.
Terms     Privacy     Licensing       EULA       Sitemap      
© Data & Object Factory, LLC.
Made with    in Austin, Texas