Object factories are special metaobjects that are used to instantiate and initialize managed objects (including its properties).
They are used by the Core to either instantiate new objects, migrated objects or object replicas. You can use them to create new objects too. However, using the CreateObject helper class as described in Section 4.3.2, “Instantiation and Finalization” is the recommended way to instantiate new objects.
One special object factory class is generated for each managed class; all of them inherit from Massiv::Core::ObjectFactory.
The object factories need an information about the inheritance hierarchy of their associated object to be able to properly initialize it. They also need information about its properties, etc. Therefore, each object factory keeps a reference to the metaobject associated with the same class as the relevant factory. That's one of the reasons why metaobjects are essential in the Massiv. An object factory for any object can be obtained from the ObjectManager.
The following list summarizes public methods contained withing an object factory class:
create_object() creates a new instance of a relevant managed class.
create_object( object_id ) creates an instance of the relevant managed class using a specified object_id. This is useful for example when creating objects from archive (the user code will never create objects from archives itself, but despite that there might exist a reasonable usage for this method in the user code).
create_replica( object_id ) creates replica of the relevant managed class. The given object_id must be the same as of the original objects. The user code typically won't use this method because there exist more comfortable methods of requesting replication. See Chapter 7, Replication for more information.
clone_object( object ) makes a duplicate of the given object using the shallow-copy technique (i.e. there won't be shared properties between the two objects, etc).
raise_exception( object ) throws an object as an exception by value.