Root classes
Overview
Root classes are top level classes that generalize all other classes.
The "Object" class
The "Object"
class is the basic class of all the classes present in the J language. All classes, including basic classes (integer, String,
etc.), specialize the "Object" class.
|
The
... operator |
corresponds
to ... |
|
== |
reference equality |
|
!= |
reference inequality |
The Object[ ] class
The Object[]
class represents a set of objects, whatever their nature. It specializes "Object".
A
constructor exists with the set type written "SetOf" that can
be associated to any J class. The type built
in this way specializes Object[].
It is thus possible to handle String[]
or Attribute[].
Note: Sets whose
elements are sets are not currently implemented. For information on set handling services,
please see "Messages to
sets (spreading)".
The "Metaclass" class
J classes, either primitive classes like "int" or UML metaclasses such as "Association", are all instances of the "Metaclass" class. This means that without knowing which element is being handled, it is possible to find out its "Metaclass", and then to discover its metaclass name, followed by its parent metaclasses.
All the
classes present in the J language are instances of the "Metaclass"
class.
Having access to the "meta metamodel" means that more generic processing can be carried out using the J language. This mechanism is similar to the Java introspection mechanism.
Changes to the metamodel in J are not permitted (only changes to the model). Introspection services are, therefore, limited.
ClassOf
MetaClass Object:
ClassOf()
"ClassOf" returns an object's metaclass.
Name
String MetaClass: Name()
"Name"
returns the metaclass name.
String Object: metaclassName()
Shortcut to obtain the metaclass name of an element.
Symbolic access
to metamodel features
boolean Object:getFeature (in String feature, out Object value)
Returns the value of "feature" in
"value" for the current object. "feature"
is either an attribute, or a dependency with a destination class. The return is
true if "feature" is defined on the current object.
Example: We are going to use "getFeature"
to recover the name and features of a class:
String name;
Feature[]
features;
Object o;
this.getFeature("Name",
o);
name ?= o;
getFeature("PartFeature",
o);
features ?= o;
ParentOf
MetaClass MetaClass: ParentOf() return MetaClass
"ParentOf"
returns the parent metaclass of the current class
or returns empty if no parent class exists.
Example:
In this
example, we are going to display the name of the metaclass and the name of the
parent metaclass of any object.
Note: This
example can be run with the "dump" command on any model
element ("Object").
Object:dump()
{
MetaClass Mclass = ClassOf();
StdOut.write("Metaclass : ", Mclass.Name, NL);
Mclass.ParentOf()
{
StdOut.write("Parent metaclass: ", Name, NL);
}
}