-
Notifications
You must be signed in to change notification settings - Fork 103
Class, Interface, and Mixin
JSX adopts a single-root, single-inheritance class model with support for interfaces and mixins.
A class in JSX have following characteristics.
- all classes derive from the built-in Object class
- single inheritance using the extends keyword
- more than one interfaces and mixins can be implemented using the implements keyword
For example, "class E extends A implements C, D" means: C can override members of A (*1), D can override members of the production of *1 (*2), and that E can override members of the production of *2.
A class may have the following attributes set.
Name | Description |
---|---|
abstract | a class with abstract methods should have the attribute set |
final | declares that the class may not be extended |
An user-defined class may have zero ore more functions or variables.
The example below defines a class called Human with a member variable _name, constructor function that takes a string as an argument, and a non-static member function (i.e. method) called say, that does not take any arguments and returns void).
class Human {
var _name : string;
function constructor(name : string) {
this._name = name;
}
function say() : void {
log "My name is " + this._name;
}
}
A function may have the following attributes set.
Name | Description |
---|---|
abstract | declares that the function should be overridden by a class that extends the class |
final | declares that the function may not be overridden |
static | declares that the function is static |
override | declares that the definition of the function is overriding an definition in the extended class (or implemented interface or mixin). A function overriding an existing function should have the attribute set |
A member variable may have the following attributes set.
Name | Description |
---|---|
abstract | declares that the variable should be defined in a class that extends the class |
static | declares thet tha variable is static |
An interface in JSX is similar to that of Java, except for the fact that it may have abstract variables. All the non-static functions are implicitly marked as abstract, and they cannot have bodies. An interface may implement other intefaces.
Mixin is provided so that implementations can be shared between classes. Mixins may implement interfaces or other mixins. It may have functions with body or non-abstract variables.