H (Hybrid) Language - v0.03, by Dr. Herong Yang
$instance Statement - Define Instance Template
This section describes the $instance statement for defining instance template.
The $instance statement is for defining instance properties and methods within the class definition body using the following syntax:
$class class_name: { ... $instance template_name: { template_name.property_name = ...; ... $method template_name.method_name(): {...}; ... } }
The instance template is like a model house created by the builder to show to potential clients. If a client like it and order for a new house, the builder will create a copy of the model house and give it the client.
Back to the H language, if you like what you see in the instance template, the list of properties and methods, you call the class constructor function to create a new instance (or object).
Example of $instance statements:
$class user: { # $instance statement to define an instance template $instance x: { x.login = "guest"; x.password = "DontTell"; $method x.changePassword(newPassword): { x.password = newPassword; } } }
Design options:
1. Use $instance as the keyword for defining the instance template.
2. Use $template as the keyword for defining the instance template.
Table of Contents
$class Statement - Create New Classes
Execution of $class Definition Body
__new() - Object Constructor Function
►$instance Statement - Define Instance Template
Execution of $instance Definition Body
$method Statement - Define Object Method
_first() Method - Object Initialization
Access Class Variables from Object Methods
__delete() - Object Destructor Method
$delete Statement - Delete Objects
_last() Method - Object Cleanup
Inheritance - Object Attachments