When to Use a Factory Pattern You should consider using a Factory pattern when · A class can’t anticipate which kind of class of objects it must create. · A class uses its subclasses to specify which objects it creates. · You want to localize the knowledge of which class gets created. There are several similar variations on the factory pattern to recognize. 1. The base class is abstract and the pattern must return a complete working class. 2. The base class contains default methods and is only subclassed for cases where the default methods are insufficient. 3. Parameters are passed to the factory telling it which of several class types to return. In this case the classes may share the same method names but may do something quite different.
Comments
Post a Comment