|
Classes 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. Classes can have a single special method called constructor. The constructor has the same name as the class and it is defined implicitly when the def or defenv tag is used to define the class. Object Creation 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.Example:
Example:
Inheritance
The 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. Example:
Example:
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.
Example:
Environment Classes 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.Example:
Classes without Constructors Using the defclass tag, classes without constructors can be defined. A class defined with defclass either inherits a constructor, or it stays an abstract class.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. Nested Classes 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.Example:
© 1996-2008 H.E.I. All Rights Reserved | |||||||||||||||||||||||||||