CLASS-ENDCLASS

Define a class

WTSupported in traditional Synergy on Windows
WNSupported in Synergy .NET on Windows
USupported on UNIX
VSupported on OpenVMS
[access] [class_mod] CLASS name[<T[(constraints)], ...>] [EXTENDS class] 
&        [IMPLEMENTS interface, ...][INHERITS [class,] [interface[, ...]]]
  member_def
  .
  .
  .
ENDCLASS

Arguments

access

(optional) One of the following access modifiers:

PUBLIC

Access is not restricted. This is the most accessible option. (default)

PROTECTED

Access is limited to the containing class or types derived from the containing class.

PRIVATE

Access is limited to the containing type. This is the least accessible option.

INTERNAL

Access is limited to the current assembly. (Synergy .NET only)

PROTECTED INTERNAL

Access is limited to the current assembly and types derived from the containing class. (Synergy .NET only)

class_mod

(optional) One or more of the following class modifiers:

ABSTRACT

The class cannot be instantiated.

CLS

The class is restricted to CLS public members. (Synergy .NET only)

PARTIAL

The class definition can be separated into two or more definitions that will be compiled together as a single definition.

SEALED

The class cannot be extended.

STATIC

The class is implicitly sealed, which means you cannot derive from it. Only STATIC members are allowed in a STATIC class.

name

The name of the class to define.

T

A generic type parameter, which indicates the class is a generic type and which acts as a placeholder for which an actual type will be substituted when the member is used. Note that you can use any unused letter (not just T). See Generic types (.NET) for more information. (Synergy .NET only)

constraints

One or more of the following constraints:

Multiple constraints must be separated by commas. See Constraints for more information. (Synergy .NET only)

EXTENDS class

(optional) The class will extend the specified parent class and will thus inherit members from that parent class. See the Discussion for more information.

IMPLEMENTS interface

(optional) Specifies one or more interface names to implement. Multiple interfaces must be separated by commas.

member_def

The declaration of a method, function, subroutine, field, property, indexer, structure, operator, delegate, enumeration, event, or nested class within the class. You can specify as many member definitions as you want, although you must specify at least one.

INHERITS [class][, interface]

(optional) Specifies the name of one parent class from which the class inherits and/or one or more interface names to implement. If the interface is preceded by a class name, it must also be preceded by a comma. Multiple interfaces must be separated by commas. We recommend that you use EXTENDS and/or IMPLEMENTS instead of INHERITS, which is only supported for code conversion purposes. (Synergy .NET only)

Discussion

The CLASS-ENDCLASS statement declares a class in the current namespace or within another class.

SEALED and ABSTRACT are mutually exclusive. Typically, an ABSTRACT class contains one or more abstract methods and/or properties. Abstract methods can only exist in abstract classes.

Using the PARTIAL modifier, it is possible to split the definition of a class over two or more source files. Each source file contains part of the class definition, and all of these parts are combined when your application is compiled, as long as no syntax errors or naming collisions exist in the partial class declarations. You may want to split a class definition when working on a large project, for example, to enable multiple developers to work on different parts of the class simultaneously. Partial classes must be compiled together at the same time (as a single compilation unit); they can’t be split across compilation units.

If the EXTENDS option is not specified, the compiler assumes the parent class is the System.Object class (which is the ultimate parent class of all objects). When a class extends a parent class, it inherits the following members from the immediate parent class, as well as any members that the parent inherits from its parent, in recursive fashion:

If parent is a fully qualified class name, the class definition is implicitly imported.

Important

Neither a common record nor a global data section may be declared within a class.

An interface enables you to define required features, avoid changes that can break your program, and enforce consistent class design throughout different implementations. A class member can implement an interface member if the following criteria are met:

When you declare that a class implements an interface, that class, or one of its ancestors, must implement all members in the interface as well as any interfaces from which that interface inherits.

You can declare an explicit interface member by prefixing the interface name and a dot (.) to the class member name. This is particularly useful if a class implements more than one interface with the same member names that require different implementations. This rule applies to all interface members.

For example, you could declare a method that implements interface Iface.mymethod as follows:

public class class1 implements Iface
public method Iface.mymethod, void
proc
    mreturn
endmethod
endclass

Explicit interface members are only accessible via a variable of that interface type. For example, if you wanted to access Iface.mymethod, you would need to do the following:

var1, @Iface
var1 = (Iface)obj
var1.mymethod()

Nested class requirements

Nested classes have the same requirements as regular classes, with the following exceptions:

See Nested classes for more information.

See also

Accessibility

Examples

In the example below, class3 accesses class2’s private member m_number.

class class2
    class class3
        public method writeit, void
            c2, @class2
        proc
            open(1,o,"tt:")
            writes(1,"num="+%string(c2.m_number))
            close(1)
            mreturn
        end
    endclass
    public method class2
    proc
        m_number = 567
        mreturn
    end
    private m_number, i4
endclass

The example below creates a custom attribute by extending System.Attribute and specifying the attribute’s usage by applying the AttributeUsage attribute to the new class.

[AttributeUsage(AttributeTargets.All)]
public class MyAttribute extends System.Attribute
public method MyAttribute
    parm1, string
proc
    name = parm1
end
private name, string
endclass