The article Factories are about abstraction, not creation told what factories are for, and when they should be used. This article will show different ways to implement factories. The complexity that is needed for a factory implementation depends on the required flexibility and how much effort is needed to construct a complete instance:
- when should it be possible to configure the factory repository: can it be coded and remain fixed for a release or should it be configurable at runtime?
- does the client of a factory need to influence the subclass choice in some way?
- how complex is the algorithm to determine the correct subclass?
- how difficult is it to construct a valid instance of the required class?