Besides the two predefined classes Object and Page, new classes can be defined using the def, defenv, or defclass tags with inherit. Each heitml class has a name and methods. Method definitions can be placed inside class definition. Methods inside a class definition directly belong to that class. They are called nested methods in contrast to the top level methods.
An object of a particular class can be created by calling the constructor method of that class. The constructor method has the same name as the class. For top level classes (classes defined outside any other class definition) the same visibility, calling, and parameter passing rules apply as for top level methods. In addition to a normal method call, a constructor call creates an object of the current class. The constructor can access the object by using the this key word.
in contrast to that a normal method call does not create a new object but uses the default page object, since top level methods automatically belong to the predefined Page class
The newly created object can be returned as a function result, as an output parameter, or stored in a global variable.
Inheritance means that all methods that belong (directly or indirectly) to the superclasses (indirectly) belong to the defined class unless they are explicitly overwritten. A method can be overwritten by a method with the same name, in the defined class or in a superclass later in the list of superclasses.
Class based Method Call
Nested methods that (directly or indirectly through inheritance) belong to a class are visible within this class, i.e. in all methods defined in this class (including the constructor). Directly defined methods are visible after the class definition.
Nested methods are only visible inside classes that define or inherit them and inside environment classes.
Visible nested methods can be called using the tag syntax, just as top level methods. Calling a method implicitly passes the current object (i.e. the object that can be accessed by this) to the called method.
A call always calls the method of the class of the current object with the given name. This feature is known as virtual method call. In fact, not always the same method is called, but the method called depends on class of the current object.
Please note, that the myclass3 object inherits the dowork method of the mysuper class. The dowork method in turn calls printme. Since printme has been overwritten, the printme method of myclass3 is called when the current object is of class myclass3.
Object Method Call
If x is an object and m a method then x.m() calls the method m of the class x belongs to. This feature is known as virtual method call since the method to be called is not fixed but is variable depending on what class the object x belongs to.
Classes with an environment as constructor have the following additional features. Inside the content of the environment the methods of the class are visible. This means inside the content methods can be called directly using the tag syntax. The methods are not visible inside the content of any nested environments. Inside the content the object of the enclosing constructor can be accessed by parent.
Classes without Constructors
It is useful to inherit a constructor, if the behavior of a class needs to be change by overriding some methods, without changing the constructor. This is useful for example to override the action routine of a button.
Abstract classes are useful to encapsulate some functionality that can be inherited by other classes. It is not possible to create object for an abstract class, because there is no constructor.
Classes can be nested, i.e. inside a class another class can be defined. The constructor of the nested class has the same visibility as a method designed in the same class. Otherwise the class acts as if it was defined on top level. So methods of the parent class are not visible inside a nested class. The constructor method is partly a constructor of the nested class and partly a method of the enclosing class. It has the same visibility as any other method of the enclosing class and it gets the current object as a parameter. Since the constructor creates a new object however the passed current object is accessible using creator, while this denotes the newly created object.
© 1996-2017 H.E.I. All Rights Reserved.