Are you talking about a Factory method or an abstract Factory?
The main problem that both are solved is to allow clients to specify the exact class that creates the code construct. For example, if you provide an interface that clients can implement, and then in your code there is something like:
IMyInterface x = new ConcreteClass();
Customers have no way to change the exact class that was created without access to this code.
A Factory Method is a virtual method that creates a specific class of a particular interface. Your code clients can provide an object that overrides this method to select the class they want to create. It might look like this in your code:
IMyInterface x = factory.Create();
factory was passed by the client and implements an interface containing Create () - they can choose the exact class.
The Factory Summary should be used if you have hierarchies of related objects, and they should be able to write code that only leads to the underlying interfaces. The Factory annotation contains several Factory methods that create a specific concrete object from each hierarchy.
In the book "Samples of drawings" "Gangs of four" they give an example of a maze with rooms, walls and doors. The client code may look like this:
IRoom r = mazeFactory.CreateRoom(); IWall nw = mazeFactory.CreateWall(); IWall sw = mazeFactory.CreateWall(); IWall ew = mazeFactory.CreateWall(); IWall ww = mazeFactory.CreateWall(); r.AddNorthWall(nw); r.AddSouthWall(sw); r.AddEastWall(ew); r.AddWestWall(ww);
(etc.)
Exact concrete walls, rooms, doors can be decided by the mazeFactory developer, who will implement the interface you provide (IMazeFactory).
So, if you provide the interfaces or abstract classes that you expect from other people to implement and provide, then factories are a way for them to also provide a way for your code to create its own specific classes when you need them.