Chapter 3 The Application Description Language

3.20 Class Definition

In the ADL, a user can define a new class from scratch (user-defined), create a subclass of a user-defined class, or create a subclass of a wrapped (system-defined) class. Class definitions can nest and you can define a class within another class, but not within its methods.

There are two forms for class definitions. The more common form defines a named class from which the user will later declare several instances. Such a class definition introduces a new type name into the ADL just as it does in C++. It consists of the following:

You can declare instance variables of the defined class immediately by appending their names after the closing curly bracket of the class definition.

The second form defines an unnamed class, and is used when all the instances of the unnamed class can be declared at the time the class itself is defined. This form of the class definition substitutes the key word anonymous for class and omits the class name. By default, all instances of a class contain their own copies of class data members. If the intention of the application developer is that all class instances should share one copy of a data member, then that data member's declaration should be prefaced with the common keyword (unimplemented). Common members correspond to the static class members of C++. The ADL has adopted a different nomenclature because the word static is overused in C++.[10]

A subclass can redefine a member or method of a parent class. Such a redefinition is said to hide the original member or method definition in the parent class. That is, the subclass cannot access the parent member or method without using a scoping operator (::) (see Section 3.24, "Inheritance" page 47).

AM2 currently provides only primitive access control to limit the developer's ability to get and set the values of a class instances members. The ADL does not possess a scheme similar to the C++ categories of public, protected, and private members. In C++ all access control is checked at compile-time, which is possible because of the language's strict type checking. The ADL is less strictly typed (handles form a single type), which forces any access control to be implemented using run-time mechanisms. We believe that it would be too computationally-intensive to implement the three C++ access categories. One possibility under consideration is to dispense with the protected category and to modify the private category so that private members and methods of an object could only be accessed from within that object itself. In C++, private methods can be called on an object from any object of the same class. The developer can use Set_ methods (see Section 3.19, "Object Member Reference" page 38) to make a member read-only in methods outside the immediate class and or in class methods applied to other instances of the same class.

Since wrapped classes are system-defined you cannot modify them, but you can create subclasses. One of the great strengths of the AM2 environment is that wrapped classes are almost indistinguishable from user-defined classes, yet they are implemented in C++ and may interface to third-party libraries. The following section discusses wrapped classes and the relationship to user-defined classes in more detail.


[10] See B. Stroustrup, The C++ Programming Language2 (1991) 166.
AM2 Documentation - 19 NOV 1996

Generated with Harlequin WebMaker