18

Object Layer

The Object Layer implements the containers for So-o classes and instances and all the functions needed by the Root class.

All the code for the So-o Object Layer is in the file OL.js.

Note that only the So-o interface functions and the methods of the Root class access this code.

  1. export function Definition(cname, sc, rev, cprops, iprops, cmsgs, imsgs) {

The container for a class is function called Definition. It has 7 arguments.

cname specifies the name of the class, a valid variable name.

rev is the revision number of the class, an integer > 0.

sc is the global reference of the superclass of the new class. If sc is null, the new class inherits by default from the Root class defined by the global variable Root.

cprops and iprops list the properties of the class and instances of the class. A property is a string. A list of properties is an array or null.

cmsgs and imsgs are associative lists of messages and methods of the class and instances of the class. A message is a string. A method is the code of a function. A list of messages and methods is an objet or null.

  1.     const varname= /^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*/;
  2.  
  3.     if (! (typeof cname === 'string' && cname.match(varname)))
  4.         throw new TypeError();

Checks if the class name is a string and a valid variable name. Triggers a TypeError exception in case of error.

  1.     if (! (sc === null || (typeof sc === 'object' && sc.prototype instanceof Definition)))
  2.         throw new TypeError();

Checks if the superclass is either null or a class. Triggers a TypeError exception in case of error.

  1.     if (!(Number.isInteger(rev) && rev > 0))
  2.         throw new TypeError();

Checks if the revision number is an integer > 0. Triggers a TypeError exception in case of error.

  1.     this.prototype = Object.create(Definition.prototype);

Initializes the new Definition.

  1.     this.name = cname;
  2.     this.revision = rev;
  3.     this.superclass = 'Root' !== cname ? (sc ? sc : Root) : null;
  4.     this.cproperties = cprops;
  5.     this.iproperties = iprops;
  6.     this.cmessages = cmsgs;
  7.     this.imessages = imsgs;

If sc is null, the superclass of the class is set to Root except for the Root class which is the only class without a superclass.

  1.     this.attributes = {};
  2. }

An object contains the values of the properties of a class.

NOTE: Only the defclass function of the interface can construct a Definition.

  1. Definition.prototype.toString = function() {
  2.     return 'class(' + this.name + ')';
  3. };

The string representation of a class returns the word class followed by the name of the class between parenthesis.

  1. Definition.prototype.sendself = function(msg, args) {
  2.     return class_send_message(this, msg, args);
  3. }

sendself sends msg with args in argument to the class. args is an array. sendself simply returns the result of calling class_send_message with the class, the message and the parameters of the message in argument.

NOTE: Only the sendmsg function of the interface calls the sendself method of a Definition.

  1. Definition.prototype.sendsuper = function(fc, msg, args) {
  2.     return class_super_send_message(fc, this, msg, args);
  3. }

sendsuper sends msg with $rgs in argument to the class, in the context of the class fc. args is an array. sendsuper returns the result of calling class_super_send_message with the class of the calling method, the class, the message and the parameters of the message in argument.

NOTE: Only the supersend function of the interface calls the sendsuper method of a Definition.

  1. export function Instance(c) {

The container for an instance is function called Instance. It has 1 argument.

c is the global reference of the class of the new instance.

  1.     if (! (typeof c === 'object' && c.prototype instanceof Definition))
  2.         throw new TypeError();

Checks if the class is a Definition. Triggers a TypeError exception in case of error.

  1.     this.prototype = Object.create(Instance.prototype);

Initializes the new Instance.

  1.  
  2.     this.class = c;

Links the instance to its class.

  1.     this.attributes = {};
  2. }

An object contains the values of the properties of an instance.

NOTE: Only the class_make function can construct an Instance.

  1. Instance.prototype.toString = function() {
  2.     return 'object(' + this.class.name + ')';
  3. };

The string representation of an instance returns the word object followed by the name of the class of the instance between parenthesis..

  1. Instance.prototype.sendself = function(msg, args) {
  2.     return object_send_message(this, msg, args);
  3. }

sendself sends msg with args in argument to the instance. args is an array. sendself returns the result of calling object_send_message with the instance, the message and the parameters of the message in argument.

NOTE: Only the sendmsg function of the interface calls the sendself method of an Instance.

  1. Instance.prototype.sendsuper = function(fc, msg, args) {
  2.     return object_super_send_message(fc, this, msg, args);
  3. }

sendsuper sends msg with args in argument to the instance, in the context of the class fc. sendsuper returns the result of calling object_super_send_message with the class of the calling method, the instance, the message and the parameters of the message in argument.

NOTE: Only the supersend function of the interface calls the sendsuper method of an Instance.

The rest of the code implements all the functions of the Object Layer which are needed by the Root class.

class_class_method_symbol
Returns the name of a class method.
class_instance_method_symbol
Returns the name of an instance method.
class_name
Returns the name of a class.
class_revision
Returns the revision number of a class.
class_superclass
Returns the superclass of a class.
class_class_properties
Returns the class properties defined by a class.
class_instance_properties
Returns the instance properties defined by a class.
class_class_messages
Returns the class messages defined by a class.
class_instance_messages
Returns the instance messages defined by a class.
class_set_class_properties
Initializes the class properties of a class.
class_set_instance_properties
Initializes the instance properties of a class.
class_set_class_messages
Initializes the class messages of a class.
class_set_instance_messages
Initializes the instance messages of a class.
class_add_class_message
Adds a class message to a class.
class_remove_class_message
Removes a class message from a class.
class_add_instance_message
Adds an instance message to a class.
class_remove_instance_message
Removes an instance message from a class.
class_add_class_property
Adds a class property to a class.
class_remove_class_property
Removes a class property from a class.
class_add_instance_property
Adds an instance property to a class.
class_remove_instance_property
Removes an instance property from a class.
class_attributes
Returns the values of the properties of a class.
class_set_attributes
Initializes the values of the properties of a class.
class_is_kind_of
Checks if a class is a subclass of another class.
class_get
Returns the value of a property of a class.
class_set
Modifies the value of a property of a class.
class_make
Returns a new instance of a class.
object_class
Returns the class of an instance.
object_superclass
Returns the superclass of an instance.
object_assume
Changes the class of an instance.
object_attributes
Returns the values of the properties of an instance.
object_set_attributes
Initializes the values of the properties of an instance.
object_get
Returns the value of a property of an instance.
object_set
Initializes the value of a property of an instance.
object_copy
Returns a copy of an instance.
class_find_class_property
Checks if a class property of a class exists.
class_find_instance_property
Checks if an instance property of a class exists.
class_find_class_method_class
Returns the class which implements a class message.
class_find_class_method
Returns the function which implements a class message.
class_find_instance_method_class
Returns the class which implements an instance message.
class_find_instance_method
Returns the function which implements an instance message.
class_apply_method
Runs a class method.
class_send_message
Executes a class message.
class_super_send_message
Executes a class message inherited from a superclass.
object_apply_method
Runs an instance method.
object_send_message
Executes an instance message.
object_super_send_message
Executes an instance message inherited from a superclass.
SEE ALSO

Interface, Root

Comments

Your comment:
[p] [b] [i] [u] [s] [quote] [pre] [br] [code] [url] [email] strip help 2000

Enter a maximum of 2000 characters.
Improve the presentation of your text with the following formatting tags:
[p]paragraph[/p], [b]bold[/b], [i]italics[/i], [u]underline[/u], [s]strike[/s], [quote]citation[/quote], [pre]as is[/pre], [br]line break,
[url]http://www.izend.org[/url], [url=http://www.izend.org]site[/url], [email]izend@izend.org[/email], [email=izend@izend.org]izend[/email],
[code]command[/code], [code=language]source code in c, java, php, html, javascript, xml, css, sql, bash, dos, make, etc.[/code].