Originally posted by Ilja Preuss:
Where does the Factory pattern come from? It's not a GoF pattern, as far as I can tell.
I have read about it in a book "Design Pattern" by James W. Cooper. Here in this book , there a Facorty Pattern defined under creational pattern section.
According to that book :-
A Factory pattern is one that returns an instance
of one of several possible classes depending on the data provided to it.
Usually all of the classes it returns have a common parent class and common
methods, but each of them performs a task differently and is optimized for
different kinds of data.
Purpose of Factory Pattern:-
In this pattern , user creates an abstraction which decides which of several possible classes to return and returns one. Then user calls the methods of that class instance without ever knowing which derived class user is actually using. This approach keeps the issues of data dependence separated from the classes� useful methods.
and I wanted to know:-
I am able to implement the same logic either with factory pattern or with Abstract factory pattern. I can create a super class which will return the instance of all the factories and which in turn can create the objects.
So if this is the scenario, then what is the actual difference between them?