The Freya Programming Language

Class inheritance

See also

Every type in Freya is defined as an extension of another already existing type, and it's called its base type or ancestor. The only exception to this rule is the predefined class System.Object, which has no ancestor.

MyControl = class(MyComponent)
public
    // ...
end;

Inheritance and polymorphism

Before the arrival of Object Oriented Programming, strong typed languages exhibited very strict rules for assignment compatibility. An assignment was valid, in most cases, when both types involved were identical:

// Pre-OOP, only valid when x and y
// had the same data type.
x := y;

There were, of course, some exceptions to the rule, as when a predefined conversion could apply, but that was the exception, not the rule.

Object Oriented Programming Languages have relaxed the compatibility rule while keeping the safety a static checked type system provides. Given an assignment like this:

x := y;

the new polymorphic assignment compatibility rule says the statement is valid when:

Of course, this is only part of the truth. Interface types, for instance, add more cases to the polymorphic compatibility rules.

Sealed classes

You can derive a new class from any existing class, unless that class has being declared a sealed class.

Sphere = sealed class(Shape)
public
    // ...
end;

All record, enumerative and delegate types are automatically considered as sealed types.

See also

The Freya Programming Language
Type declarations
Class declarations
Interface types
Implementing an interface