Back to list
Views:   9.9K
Replies:  1
Archived

GoF Design Patterns 4.0 pdf question #2

This is in regards to Factory Method.

The PDF states (page 16)

"So, when do you know the Factory Method is at work? The rules are:

- the method creates a new object

- the method returns an abstract class or interface

- the abstract class or interface is implemented by several classes "

So, it seems that for a method that creates a class, for it to be a Factory Method, it should return an abstract class or interface, right?  Seems clear, but I'm kinda wondering the difference between Factory Method and Abstract Factory.  Fortunately this is answered on page 17:

"This is exactly where Abstract Factory and Factory Method differ: Abstract Factory methods are virtual or abstract and return abstract classes or interfaces. Factory Methods are abstract and return class types. "

It seems this conflicts with the statement that "Factory Methods return abstract classes or interface" when it this says "Factory Methods are abstract and return class types".

Anybody have an explanation?

Thanks

Mike Michaelis, Dec 10, 2010
Reply 1
The difference between Abstract Factory and Factory Method has been blurred over the years.  If you look at differences between the original GOF UML diagrams of Abstract Factory and Factory Method you see in Abstract Factory ┬┤a higher level of abstraction┬┤ (there are several abstract types involved, hence the name Abstract Factory). 

To alleviate any confusion, we should probably remove the sentence:  "This is exactly where Abstract Factory and Factory Method differ: Abstract Factory methods are virtual or abstract and return abstract classes or interfaces. Factory Methods are abstract and return class types. "

The sentence is generally true, but there are most likely edge cases where things are done differently. Also, it would probably be safer to state that methods in Factories (both types) return classes, abstract classes, or interfaces. This would cover all possible factory implementations. 








Dan McMillan, Dec 12, 2010
Hi Dan, Thanks for the advice. I tried what you mentioned but not working. Let me give you the environment I am working on. Stand alone laptop with Windows 7 (ultimate edition). SQL server 2008 developer edition Sql server 2008 R2 Express edition (removed now) Sql server 2005 Express edition with SP2 Visual studio 2010 ultimate edition I made a small change in WCF application app config for localsqlserver to point SQL server 2008 developer edition (where i have aspnetdb). So now atleast the login part is working. But failing at GetCustomers in Model.cs with the error message 'The underlying provider failed to open'. There is a image of error attached with this post. I tried to attach Action.mdf and aspnetdb.mdf to both the sql server instances and it failed. Basically I am trying to point at the databases in developer edition instad of attaching at runtime. Please give me some suggesstions where to make changes in the config files. Thanks Viv
Sep 04, 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