Name Collision in Attached Objects

This section describes how to resolve name collision in attached objects.

If a property name or method name in an attached object is identical to one of properties or methods in the primary object, the primary object wins.

In other words, if a property or method in an attached object is identical to one of properties or methods in the primary object, that property or method become in accessible.

Examples of name collision in attached objects:

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

$class employee: {
   $instance x: {
      x.id = 1;
      x.status = "Part-time";
	  $method x.changeStatus(newStatus): {
	     x.status = newStatus;
	  }
   }
}

e = employee();
$append e $with person();
write(e.id); # prints 1, "employee" object wins

p = person();
$append p $with employee();
write(p.id); # prints 0, "person" object wins

Last update: 2017.

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

 PDF Printing Version