Factory MethodThe book has now been published and the content of this chapter has likely changed substanstially.
A method that returns a new instance of a class.
A Factory Method is a method that encapsulates the logic required to construct a new object. It hides the constructor method. While a Factory Method may be a class method (a static method) on a well-known object, on an Abstract Factory[GOF] it needs to be an instance method called on an object. This allows the factory object to be replaced by a different factory objects at runtime thus allowing instances of different classes to be returned in different circumstances (such as during automated testing.)
Copyright © 2003-2008 Gerard Meszaros all rights reserved