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.
- 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
.
- const varname= /^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*/;
- if (! (typeof cname === 'string' && cname.match(varname)))
- throw new TypeError();
Checks if the class name is a string and a valid variable name. Triggers a TypeError exception in case of error.
- if (! (sc === null || (typeof sc === 'object' && sc.prototype instanceof Definition)))
- throw new TypeError();
Checks if the superclass is either null
or a class.
Triggers a TypeError exception in case of error.
- if (!(Number.isInteger(rev) && rev > 0))
- throw new TypeError();
Checks if the revision number is an integer > 0. Triggers a TypeError exception in case of error.
- this.prototype = Object.create(Definition.prototype);
Initializes the new Definition.
- this.name = cname;
- this.revision = rev;
- this.superclass = 'Root' !== cname ? (sc ? sc : Root) : null;
- this.cproperties = cprops;
- this.iproperties = iprops;
- this.cmessages = cmsgs;
- 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.
- this.attributes = {};
- }
An object contains the values of the properties of a class.
NOTE: Only the defclass
function of the interface can construct a Definition.
- Definition.prototype.toString = function() {
- return 'class(' + this.name + ')';
- };
The string representation of a class returns the word class
followed by the name of the class between parenthesis.
- Definition.prototype.sendself = function(msg, args) {
- return class_send_message(this, msg, args);
- }
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.
- Definition.prototype.sendsuper = function(fc, msg, args) {
- return class_super_send_message(fc, this, msg, args);
- }
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.
- 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.
- if (! (typeof c === 'object' && c.prototype instanceof Definition))
- throw new TypeError();
Checks if the class is a Definition. Triggers a TypeError exception in case of error.
- this.prototype = Object.create(Instance.prototype);
Initializes the new Instance.
- this.class = c;
Links the instance to its class.
- this.attributes = {};
- }
An object contains the values of the properties of an instance.
NOTE: Only the class_make
function can construct an Instance.
- Instance.prototype.toString = function() {
- return 'object(' + this.class.name + ')';
- };
The string representation of an instance returns the word object
followed by the name of the class of the instance between parenthesis..
- Instance.prototype.sendself = function(msg, args) {
- return object_send_message(this, msg, args);
- }
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.
- Instance.prototype.sendsuper = function(fc, msg, args) {
- return object_super_send_message(fc, this, msg, args);
- }
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.
Comments