<HTML> <HEAD> <!-- This HTML file has been created by texi2html 1.51 from ProgrammersManual.texinfo on 4 March 1997 --> <TITLE>LambdaMOO Programmer's Manual - Passing</TITLE> </HEAD> <BODY> Go to the <A HREF="ProgrammersManual_1.html">first</A>, <A HREF="ProgrammersManual_39.html">previous</A>, <A HREF="ProgrammersManual_41.html">next</A>, <A HREF="ProgrammersManual_77.html">last</A> section, <A HREF="ProgrammersManual_toc.html">table of contents</A>. <P><HR><P> <H3><A NAME="SEC40" HREF="ProgrammersManual_toc.html#TOC40">Object-Oriented Programming</A></H3> <P> One of the most important facilities in an object-oriented programming language is ability for a child object to make use of a parent's implementation of some operation, even when the child provides its own definition for that operation. The <CODE>pass()</CODE> function provides this facility in MOO. </P> <P> <DL> <DT><U>Function:</U> value <B>pass</B> <I>(<VAR>arg</VAR>, ...)</I> <DD><A NAME="IDX1"></A> Often, it is useful for a child object to define a verb that <EM>augments</EM> the behavior of a verb on its parent object. For example, in the LambdaCore database, the root object (which is an ancestor of every other object) defines a verb called <SAMP>`description'</SAMP> that simply returns the value of <CODE>this.description</CODE>; this verb is used by the implementation of the <CODE>look</CODE> command. In many cases, a programmer would like the description of some object to include some non-constant part; for example, a sentence about whether or not the object was `awake' or `sleeping'. This sentence should be added onto the end of the normal description. The programmer would like to have a means of calling the normal <CODE>description</CODE> verb and then appending the sentence onto the end of that description. The function <SAMP>`pass()'</SAMP> is for exactly such situations. </P> <P> <CODE>pass</CODE> calls the verb with the same name as the current verb but as defined on the parent of the object that defines the current verb. The arguments given to <CODE>pass</CODE> are the ones given to the called verb and the returned value of the called verb is returned from the call to <CODE>pass</CODE>. The initial value of <CODE>this</CODE> in the called verb is the same as in the calling verb. </P> <P> Thus, in the example above, the child-object's <CODE>description</CODE> verb might have the following implementation: </P> <PRE> return pass() + " It is " + (this.awake ? "awake." | "sleeping."); </PRE> <P> That is, it calls its parent's <CODE>description</CODE> verb and then appends to the result a sentence whose content is computed based on the value of a property on the object. </P> <P> In almost all cases, you will want to call <SAMP>`pass()'</SAMP> with the same arguments as were given to the current verb. This is easy to write in MOO; just call <CODE>pass(@args)</CODE>. </DL> </P> <P><HR><P> Go to the <A HREF="ProgrammersManual_1.html">first</A>, <A HREF="ProgrammersManual_39.html">previous</A>, <A HREF="ProgrammersManual_41.html">next</A>, <A HREF="ProgrammersManual_77.html">last</A> section, <A HREF="ProgrammersManual_toc.html">table of contents</A>. </BODY> </HTML>