Inheriting class functionality and data

An extending class inherits the following members from the immediate parent class, as well as any members that the parent inherits from its parent, in recursive fashion:

After you extend the class, you can override inherited methods and provide additional methods, fields, or properties.

To extend a class,

1. Create a class as instructed in Creating a class.
2. Multiple namespaces can exist in a single source file. If the parent class is not in the same namespace as the class added in step 1, add an IMPORT statement to the class file to import the namespace of the parent class definition, specifying the namespace of the parent class. (If the parent class is in the same namespace as the class added in step 1, an explicit IMPORT statement is not required, because the parent class is imported implicitly.)
3. Using the EXTENDS modifier, add the parent class name to the class declaration.

For example,

public class class1 extends myparentclass
  ; put class members here
endclass
4. For all parent class methods or properties that you want to override, add a method or property declaration and implementation to the new (derived) class and specify the OVERRIDE modifier. The signature for the method must match the signature for the parent class method that’s being overridden. The parent class method must be marked as VIRTUAL, ABSTRACT, or OVERRIDE.
5. (optional) Add additional methods, fields, and properties to the child class that are not found in the parent class.
6. Save the source file.
7. (traditional Synergy only) Compile the source file into a .dbo file.
8. (traditional Synergy only) Run the Synergy prototype utility against the source file to export the new class definition. (If you only want to use the class locally, you can skip this step.)

If you don’t use the EXTENDS modifier, the class extends the system object (System.Object).

Constructors and destructors are not inherited.

Accessing members of the current instance or base class

The this and parent keywords enable you to access members of a class depending on the context.

This refers to the current instance of the class. You can use it to qualify members hidden by identical names. For example,

this.name
method_name(this)

Parent is used to access members of the base class from within a derived class. You can use it to call a method on the base class that was overriden by another method or to specify which base-class constructor should be called when creating instances of the derived class. For example,

parent.name

The base class that is accessed is the base class specified in the class declaration. For example, if you specify

class ClassB extends ClassA

the members of ClassA are accessed from ClassB, regardless of the base class of ClassA.

Parent is allowed in a constructor or an instance method.

An error will occur if you refer to this or parent from within a static method.

See Constructors and destructors for more information about using this and parent to declare initializers in a construcgtor.