Calling the Superclass Builder
Now you have a complete system of two classes: the abstract class element, and the specific class arrayelement that extends it. Perhaps you are still imagining other ways of expressing elements. For example, a customer might want to create a layout element that is composed of a given single-line string. Object-oriented programming makes it easy to extend a system with new data variants. Just add a subclass. For example, code 10.6 shows the Lineelement class for extending arrayelement:
Class Lineelement (s:string) extends
arrayelement (Array (s)) {
override def width = s.length
override de F height = 1
}
Code 10.6 calls the superclass constructor
Because the lineelement extends the arrayelement and the Arrayelement constructor takes a parameter (array[string]), Lineelement needs to pass a parameter to the main constructor of its superclass. To invoke a superclass constructor, simply place the argument or argument list you want to pass in parentheses after the superclass name. For example, class Lineelement passes the main constructor of array (s) to arrayelement, placing it in parentheses behind the name of the superclass arrayelement:
... extends Arrayelement (Array (s)) ...
With the new subclass, the inheritance level of the layout element now looks like it was shown in emoticons 10.2.
Class diagram of 10.2 lineelement of emoticons