Object Morphinism by Changing Attachments

This section describes how to provide object morphinism by changing appended objects.

Object morphinism can be supported by changing append objects as shown in the example below:

$class egg: {...};
$class larva: {...};
$class pupa: {...};
$class butterfly: {...}; 

$class pieridae: {
   $instance x: {
      x.stage = "egg";
      $method x._first(): {
	     $append x $with egg();
	  };
	  $method x.hatch(): {
	     $trim x;
		 $append x $with larva();
	  };
	  $method x.cocoon(): {
	     $trim x;
		 $append x $with pupa();
	  };
	  $method x.transform(): {
	     $trim x;
		 $append x $with butterfly();
	  };
	  $method x.layEggs(): {...};
   };
};

# life of a pieridae starts with an egg
life = pieridae();

# the egg hatches into a larva under the right condition
life.hatch();

# the larva eats and builds a cocoon to becomes a pupa 
life.cocoon();

# the pupa transforms into a butterfly
life.transform();

# the butterfly lays more eggs
life.layEggs();

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