In abstract factory you declare a type which is responsible for creating objects.
This would prevent requiring switch's like this:
if( type == ONE ) {
doOne();
} else if( type == TWO ) {
doTwo();
} etc.
Or the same:
switch( type ) {
case ONE: doOne(); break;
case TWO: doTwo(); break;
etc....
}
Into this:
MyAbstractFactory factoryInstance = ... ?
SomeObject object = factoryInstance.createObject();
object.doX();
As I understand the AbstractFactory will create the correct object which in turn will execute polymorphically the correct behavior.
Then if you use that object 10-20 or 100 times in your progam, you don't have to repeat the switch every time. You just execute the corresponding method and leave to the polymorphism do the job.
object.doY();
object.doZ();
Adding a new type is as easy as create a new concrete factory.
All this is clear to me. But...
Where or how is the concrete factory created ( in general terms ) in the first place?
I have always used one single point ( usually in the main() method or in a Configuration.init() method ) which in turn do have the if/else|switch construct which is unavoidable but at least it is used only once.
However I did this "instinctively" ( or by common sense ) but never read in any of the documents describing the pattern WHERE should it be created.
:)