Specifying Class Lifetimes

The Lifetime sheet of the Define Class dialog, shown in the following image, is displayed when you select the Lifetime sheet of the dialog. For details about restricting the lifetime of instances of a class and its subclasses, see "Class Lifetime Options" under "Controlling the Use of Elements in Other Schemas", in Chapter 1.

You cannot define a class when all three class or subclass options are unchecked (that is, at least one of the check boxes in the Class Lifetimes group box and one of the check boxes in the Subclass Lifetimes group box must be checked).

To define the lifetime of instances of the class and its subclasses

  1. If you do not want the class to have persistent instances, uncheck the Allow Persistent Instances check box. (This check box is disabled if the Allow Persistent Subclass Instances check box was unchecked in the superclass to which you are adding this class.)

    When this is unchecked, an exception is raised at every attempt to create a persistent instance of the class. A compiler error is raised if you attempt to construct a persistent object from within a method (that is, you call create <object-name> persistent). Persistent instances of subclasses are restricted according to the setting of the Allow Persistent Subclass Instances check box, in step 4.

  2. If you do not want the class to have non-shared transient instances, uncheck the Allow Transient Instances check box. (The Allow Transient Instances check box is disabled if the Allow Transient Subclass Instances check box was unchecked in the superclass to which you are adding this class.) When this is unchecked, an exception is raised at every attempt to create a non-shared transient instance of the class.

    A compiler error is raised if you attempt to construct a transient object from within a method (that is, you call create <object-name> transient).

    Non-shared transient instances of subclasses are restricted according to the setting of the Allow Transient Subclass Instances check box, in step 5.

  3. If you do not want the class to have shared transient instances, uncheck the Allow Shared Transient Instances check box. (The Allow Shared Transient Instances check box is disabled if the Allow Shared Transient Subclass Instances check box was unchecked in the superclass to which you are adding this class.)

    When this is unchecked, an exception is raised at every attempt to create a shared transient instance of the class. A compiler error is raised if you attempt to construct a shared transient object from within a method (that is, you call create <object-name> sharedTransient). Shared transient instances of subclasses are restricted according to the setting of the Allow Shared Transient Subclass Instances check box, in step 6.

  4. Uncheck the Allow Persistent Subclass Instances check box if you want to prevent the creation of persistent instances of subclasses. The Allow Persistent Instances and Allow Persistent Subclass Instances check boxes will then be disabled in subclass definitions so that these values cannot be changed and an exception will be raised at every attempt to create a persistent instance of a subclass.

    When the Allow Persistent Subclass Instances check box is checked, the value can be changed in subclasses (that is, persistent instances and persistent subclass instances can be allowed or disallowed).

  5. Uncheck the Allow Transient Subclass Instances check box if you want to prevent the creation of transient instances of subclasses. The Allow Transient Instances and Allow Transient Subclass Instances check boxes will then be disabled for subclass definition so that these values cannot be changed and an exception will be raised at every attempt to create a transient instance of a subclass.

    When the Allow Transient Subclass Instances check box is checked, the value can be changed in subclasses (that is, transient instances and transient subclass instances can be allowed or disallowed).

  6. Uncheck the Allow Shared Transient Subclass Instances check box if you want to prevent the creation of shared transient instances in subclasses.

    The Allow Shared Transient Instances and Allow Shared Transient Subclass Instances check boxes will then be disabled for subclass definitions so that these values cannot be changed and an exception will be raised at every attempt to create a shared transient instance of a subclass.

    When the Allow Shared Transient Subclass Instances check box is checked, the value can be changed in subclasses (that is, shared transient instances and shared transient subclass instances can be allowed or disallowed).

  7. Click the OK button. Alternatively, click the Cancel button to abandon your selections or the Next button to define another class.

Alternatively, you can select the Tuning sheet if you want to tune a Collection subclass or the Volatility sheet if you want to change the volatility of instances of the class.