Factories

A factory represents a function that can create an instance of one or more types. Calling a type's factory function is analogous to the calling operator new on a class in Java or C++. When called by the plug-in host, the factory function allocates memory for an instance of the type being requested, sets up the function tables for its interfaces, and returns a pointer to the type's IUnknown interface. The plug-in host can then use the IUnknown interface to search for other interfaces supported by the type.

When a CFPlugin is created, the system registers all types the plug-in supports along with their associated factory functions. When the plug-in host wants to create an instance of a given type, it uses the type's UUID to search for any registered factory functions. It can then use a factory function to create an instance of the type.

Note that it is possible for a plug-in to have multiple factory functions for the same type. It is up to the developer to define appropriate usage for the different functions.


© 1999 Apple Computer, Inc. (Last Updated 10 December 99)