Since Odrade agrees with me (I think I'm not quite from my rocker), I will send this as an answer:
I think, and correct me if I am wrong, is that usually your base level code does not have a clue about a specific factory. Also, you should not indicate the type of product (in your case) through prodType. Instead, a specific factory implementation is served through some form of dependency injection into your abstract factory, and your code continues its weighting path without having a clue that the factory is being used, or the specific types that are needed. Especially if specific factory implementations are provided by third-party consumers of your API.
The Wikipedia article on this subject is a good example of building a GUI for an operating system: http://en.wikipedia.org/wiki/Abstract_factory_pattern#C.23
In fact, your code in your library can function perfectly, without knowing any implementation details or dependencies on the operating system used. When you (or a user of your API) switch to Linux migration (in this example on Wikipedia), you simply implement LinuxFactory and LinuxButton and pass it to your API. If instead, as in your typical example, you control it through an input, say, an enumeration, then your factory should know about Linux:
public static class Factory { public static Button GetButton(operatingSystem) { switch (operatingSystem) { case "windows": return new WindowsButton(); case "macintosh": return new MacButton(); } } }
How is Linux now taken into account? Well, that can't unless you add support. Plus now all consumers of your API are indirectly dependent on all implementations of the operating system.
EDIT: Note that Factory Pattern and Abstract Factory Pattern are two completely different concepts. As for your problems with why you asked the question first, abstract factory templates are not always necessary. If you do not need this, then do not add the complexity of one. If you just need a simple factory (which your second example is an option), use it. The right tool for the right job and all that.
source share