Factory Methods

In TM4J, you never create TopicMapObject instances directly, instead you must use the appropriate factory method to create the object. TM4J defines a simple containment hierarchy, where parent objects "contain" zero or more "child" objects of specific types. The interface of the parent object provides methods for creating new instances of the child object. Table 3.2, “TM4J Interfaces and their relation to objects in the XTM data model and DTD” shows for each interface the "child" object types that it can create. To create such a child object you must invoke the appropriate createXXX() method on the parent object. All of these createXXX() methods take a String id parameter which specifies the unique identifier for the object to be created. This identifier must be unique across all objects in the same TopicMap. However, by passing null in for this parameter, you can pass the responsibility for generating the id string to the back-end implementation.