Factory Function

CategoryPattern -- ClassFactory

Usage:

When a "VirtualConstructor" is needed -- when you wish to select the class of objects to create at runtime.

And you don't feel the need to be "very OO."

Do:

Call a function that will create an instance of a class of its choosing, and return it to you. It may use parameters or static configuration data to select which class should be used.

This can be particularly useful in implementing the SingletonPattern, which requires careful control of object creation, but not runtime selection of class.

Function pointers can be used as super lightweight FlyweightPattern AbstractFactory-s.


EditText of this page (last edited February 15, 2002) or FindPage with title or text search