nimmi_srivastav@yahoo.com (Nimmi Srivastav) wrote...
> Can anyone kindly help me to understand, once and for all, the
> difference between the Factory design pattern and the Abstract Factory
> design pattern, as discussed in the GoF book.
The "Factory Method" pattern is a method on a class, used to build
other instances. You can implement a Factory Method on just about any
class that happens to be handy at the time.
The "Abstract Factory" pattern is about creating a class that has
nothing (of interest) other than Factory Method(s) on it. Use this
when you need to create a suite of different but matching objects, or
if the act of controlling object creation rises to the point of being
the primary function of the class.
> Are there enough differences between the two to warrant including both
> of them as separate patterns altogether.
"Should" they be separate? Well, that's entirely a matter of
subjective opinion. Personally, I tend to see them as two
implementations of the same pattern, but I could be convinced
otherwise. Don't expect the Design Patterns book to be the do-all
end-all perfect example of *THE* correct patterns. I think, for
example, that the Null Object pattern is a glaring omission of the
original book. But that's OK; there are thousands of other
interesting and relevant patterns that were also not included in the
original book. Read other books and web sites. There's a lot to
learn.