The Hyper Programming Language

Classes

General

A class in Hyper is similar to a class in C++ or Java. As it is in Java, you don't have separate header and implementation files. Class inheritance, implementing interfaces, operator overloading and generics are not yet supported. A class is placed directly inside a sourcefile or in another class.

Every type (except pointer types) is represented by a class, including the built-in types.

Syntax

A class consists of a header, a body and an end. The header is currently nothing more than just class name. The body is divided into public, protected and private sections. The end is quite flexible; it can be the full end class name, but both the class keyword and the class name are optional, so a simple end is sufficient.

You can start public, protected and private sections with public:, protected: and private:. These section headers must be on a separate line. Any content of a class that is not under a section header is private.

Access levels

The body of a class is separated into sections. Each section starts with an access specifier as described earlier. Every class member's accessibility is determined by this access specifier. public members are accessible from anywhere. protected members are accessible from within the class, and from within derived classes. private members are not accessible from anywhere but the class they are in.

Members

The members of a class can be:

Nested classes

When class A is nested inside class B, then B serves like a namespace that contains A. You don't need an object of class B to be able to use an object of class A. In Java, this would be a 'static class B' inside a class A.

`Static' classes

A static class cannot be instantiated, and it can contain only static members. `Static' classes cannot be derived from and they cannot have a protected section. Every member of such a class is implicitly also static.

`Abstract' classes

An abstract class is in C++ a class that contains pure virtual functions. An abstract class cannot be instantiated by itself but only as the base of a class that is not abstract itself.

`Sealed' classes

A sealed class is a class that cannot be derived from. All the built-in class types except for object are sealed classes.

Examples

First of all there is the Hello World example.

A class "C" that contains a public procedure "p", a protected procedure "q" and a private procedure "r":

class C
public:

  procedure p()
  end
	
protected:

  procedure q()
  end

private:

  procedure r()
  end
end C

An class containing a procedure that is implicitly private:

class MyClass
  procedure x()
  end
end

A private class A, nested inside a class B:

class B
  class A
    procedure p()
    end p
  end
end class B

See also


Valid HTML 4.01 Strict Valid CSS!