create Method Constructors

A constructor can be implemented with one or more parameters. JADE does not support method overloading, so a class can have one explicit constructor only. However, the number and type of the parameters on the create method on any class in the hierarchy can differ.

The syntax of a constructor with parameters is as follows.

create(optional‑parameters) [::super(required‑parameters)] updating;

The optional ::super value indicates that the superclass constructor is invoked with the specified parameters. For this syntax to be used, the create method in the superclass must have parameters. If the superclass constructor has parameters, the compiler verifies that the call to the constructor is present, that the number of parameters is correct, and that the types are compatible with the definition of the superclass create method. If the superclass constructor does not have parameters, an explicit call is not allowed.

The result of a method call that returns a value of the appropriate type can be provided as the value to a parameter to a superclass constructor. The receiver of the method is a partially initialized instance of the class being created. The constructor parameters for the immediate superclass and current class are not called until after the method has executed. If the method is declared on a superclass and reimplemented on the class of the instance being created, the reimplemented method implementation is called.

Changing the signature of a create method results in any methods creating an instance of the class being marked for recompile.

Parameters must be usage constant or usage input. Usage io and usage output parameters are not supported.

If a class with a constructor with parameters is exported from a package, the create method must also be exported.

JADE does not allow parameters to be declared on the create method of classes that derive from any RootSchema class other than Object. This restriction is required because when JADE instantiates instances of these classes, the parameters values are not always known. For example, Form and Control instances are created when a form is displayed, and exclusive collection instances are instantiated when the collection is populated.

See also "Using Constructors and Destructors", earlier in this chapter.

Constructor Method Example

The hierarchy in the examples of the create method with parameters syntax is as follows.

A - create() // explicit
  \
    B - create(string: String) // explicit
      \
        C - create() // explicit

The following, based on the above hierarchy, are examples of the new method syntax.

A - create() updating;
B - create(string: String) updating;
C - create() ::super("my name") updating;

When an instance of B is created, A::create() is called then B::create() is called with the parameters provided in the create instruction.

When an instance of C is created, A::create() is called and then C::create() is called. B::create() is called explicitly by C::create(), before the body of the C::create() method is executed.