Sedona

Classes

Overview

Classes are the primary way you organize your code within kits. Classes are named containers for fields and methods. A field or method definition is called a slot and identified by a unique name within a given class. Slots may not be overloaded by name, which means you cannot declare a field and method to have the same name (as allowed in Java). Nor can you declare multiple methods with the same name overloaded by parameters (as allowed in both Java and C#).

You can declare multiple classes in a single source file, although by convention each class is placed in its own source file with the same name. For example the class "Thing" would be declared in the file "Thing.sedona".

Modifiers

By default a class is public, or you can explicitly use the public keyword. Alternatively use the internal keyword to declare a class that only has visibility within its kit.

The abstract keyword is used with classes that can never be instantiated directly. Any class that declares abstract methods must be marked abstract.

Use the final class modifier to prevent a class from being subclassed.

Inheritance

The Sedona Framework supports implementation inheritance very similar to Java or C#. However, there is no support interfaces or any type of multiple inheritance.

In order to support polymorphism (virtual methods), your class hierarchy must extend from sys::Virtual, which allocates space for the virtual table. Note that Virtual imposes a two byte overhead per instance, plus a global table for each type in the code section.

The syntax for inheritance looks just like Java with the extends keyword:

abstract class Shape extends Virtual
{
  abstract int area()
}

class Square extends Shape
{
  override int area() { return width * width }
  int width
}