Build Subclasses with Superclasses

This section describes how to build subclasses with superclasses.

The $append statements inside the class definition body can be used to build subclasses with superclasses. No additional new statements needed.

In the example below, "person" is considered as a superclass; and "employee" is considered as a subclass.

$class person: {
   $instance x: {
      x.name;
	  $method x._first(name="John") {
         x.name = name;
	  }
	  $method x.changeName(name): {
	     x.name = name; 
	  }
   }
}

$class employee: {
   $instance x: {
      x.status;
	  $method x._first(name="Maria", status="Part-time") {
	     $append x $with person(name);
		 x.status = status;
	  }
	  $method x.changeStatus(status): {
	     x.status = status;
	  }
	  $method x.print(): {
	     write(x.name);
		 wirte(x.status);
	  }
   }
}

e = employee(name="Herong", status="Full-time");
e.print();

Table of Contents

 About This Book

 Introduction of H Language

 Syntax

 Data Types

 Variables

 Expressions

 Statements

 "boolean" Data Type

 "integer" Data Type

 "string" Data Type

 "real" Data Type

 "array" Data Type

 Source Code Packages

 Classes and Objects

 Object Oriented Programming

Inheritance - Object Attachments

 What Is Object Attachment

 $append Statement - Attach Objects

 Name Collision in Attached Objects

 Append Multiple Object Attachments

 $trim Statement - Detach Objects

Build Subclasses with Superclasses

 Object Morphinism by Changing Attachments

 Encapsulation - Private Members

 References

 Full Version in PDF/ePUB