Menu

Derivation

Will Pittenger

As mentioned, ASIL supports multiple derivation. Java and C# left that out so they could simplified means of generic access to those base classes. ASIL attempts to do both. Below is a sample of a class with multiple base classes. This class also implements two interfaces. (Note: If a class has only one base class, the base keyword can be used by itself without the "@" or the base class name.)

class TestClass
    inherits A, B
    implements C, D ' Assume these interfaces both require a command called "doIt" to be implemented and it takes no parameters

  public constructor
    base@A ' Normally, base class default constructors are automatically called in the order you declare the base classes in the inherits clause.  But we're doing it explicitly for demo purposes.
    base@B

    ' initialize the derived class

  public command myCommand
    base@A.baseClassCommand

  public override C.doIt
    ' handle the command

  public override D.doIt
    ' handle the command

Classes can derived from any type, even primitives, as long as they aren't marked final. So you can think of a primitive as a struct with just once field. A derived class can add fields to that primitive. A structure can also derive from any type, but with more restrictions. Structures can't inherit from types with virtual functions (except Object) or types that implement interfaces (again, except for Object). They also can't implement interfaces themselves.

Blocking access to base class member from a derived class

There are cases in which a derived class need to block access to members and methods of a base class. The syntax ASIL will use for this is still up in their air as it needs to work even if the code with an instance of the derived class has a reference to the base class. One example of such a situation would be where you derive from a collection class. The members of the collection class might not be relevant for the derived class.


Related

Wiki: Home
Wiki: Keywords
Wiki: keywords-extends
Wiki: keywords-final