Object class: Difference between revisions

From m204wiki
Jump to navigation Jump to search
 
mNo edit summary
Line 1: Line 1:
#REDIRECT [[Global and session objects#Using Object class methods to access global and session objects]]
<!-- Object class -->
The Object class is an implicit base class for '''all''' classes. However, until <var class="product">[[Sirius Mods]]</var> 8.1, there was no way to reference the Object base class via object variables of any of its extension classes (that is all classes other than the Object class) and there was no way to assign an variable of one class to a variable of its base Object class. This is all possible in <var class="product">[[Sirius Mods]]</var> 8.1.
 
In <var class="product">[[Sirius Mods]]</var> 8.1, it is possible to invoke an Object class method against any object. For example:<p class="code">b
 
%foo  is object stringlist
 
%foo = new
printText {~=%foo:className}
 
end
</p>
 
would display:<p class="code">%foo:className=System:Stringlist
</p>
 
And
<p class="code">b
class pair
  public
      variable  x is float
      variable  y is float
  end public
end class
 
%pair is object pair
%pair = new
printText {~=%pair:className}
end
</p>
 
would display:<p class="code">%pair:className=Pair
</p>
These examples illustrate that not only is the Object class an implicit base class of every class (in fact it is not permissible to explicitly declare the Object class as a base class) but that every extension class of the Object class inherits the Object class member names so that the Object class does not have to be specified on an Object class member reference. However, as with other extension classes, all classes can "hide" a base class member by containing a member with the same name. For example, if we add the member <var>ClassName</var> to class <var>Pair</var> in the above example, <code>%pair:className</code> would refer to the Pair class <var>className</var>. However, in such a case, it would be possible to reference the Object class <var>className</var> by preceding it with <code>(object)</code> as in:<p class="code">b
class pair
  public
      variable  x is float
      variable  y is float
      variable  classname is string len 32
  end public
end class
 
%pair is object pair
%pair = new
%pair:className = 'This name makes no sense'
printText {~=%pair:className}
printText {~=%pair:(object)className}
end
</p>
which displays:<p class="code">%pair:className=This name makes no sense
%pair:(object)className=Pair
</p>
==List of Object methods==
The [[List of Object methods|"List of Object methods"]] shows all the class methods, with a brief description of each.
 
[[Category:System classes]]

Revision as of 03:25, 16 July 2012

The Object class is an implicit base class for all classes. However, until Sirius Mods 8.1, there was no way to reference the Object base class via object variables of any of its extension classes (that is all classes other than the Object class) and there was no way to assign an variable of one class to a variable of its base Object class. This is all possible in Sirius Mods 8.1.

In Sirius Mods 8.1, it is possible to invoke an Object class method against any object. For example:

b %foo is object stringlist %foo = new printText {~=%foo:className} end

would display:

%foo:className=System:Stringlist

And

b class pair public variable x is float variable y is float end public end class %pair is object pair %pair = new printText {~=%pair:className} end

would display:

%pair:className=Pair

These examples illustrate that not only is the Object class an implicit base class of every class (in fact it is not permissible to explicitly declare the Object class as a base class) but that every extension class of the Object class inherits the Object class member names so that the Object class does not have to be specified on an Object class member reference. However, as with other extension classes, all classes can "hide" a base class member by containing a member with the same name. For example, if we add the member ClassName to class Pair in the above example, %pair:className would refer to the Pair class className. However, in such a case, it would be possible to reference the Object class className by preceding it with (object) as in:

b class pair public variable x is float variable y is float variable classname is string len 32 end public end class %pair is object pair %pair = new %pair:className = 'This name makes no sense' printText {~=%pair:className} printText {~=%pair:(object)className} end

which displays:

%pair:className=This name makes no sense %pair:(object)className=Pair

List of Object methods

The "List of Object methods" shows all the class methods, with a brief description of each.