| <!DOCTYPE html |
| PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "../xhtml1-strict.dtd"> |
| <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> |
| <head> |
| <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> |
| <link rel="stylesheet" type="text/css" href="../css/ot.css" /> |
| <link rel="stylesheet" type="text/css" href="../css/otjld.css" /> |
| <title>OT/J Language Definition v1.3</title> |
| </head> |
| <body class="otdt"> |
| <div id="content"> |
| <table class="nav"> |
| <tr> |
| <td class="back"><a id="top"></a></td> |
| <td class="top"><a href="index.html" rel="contents">↑ Table of Contents ↑</a></td> |
| <td class="next"><a href="s3.2.html" rel="next">§3.2 Callout parameter mapping >></a></td> |
| </tr> |
| </table> |
| <div class="breadcrumb"><a class="nav" href="s3.html" rel="section">§3 Callout Binding</a></div> |
| <div class="sect depth2" id="s3.1"> |
| <h2 class="sect">§3.1 Callout method binding<a class="img" href="s3.1.html" |
| title="PermaLink to §3.1 Callout method binding"><img style="vertical-align:text-top;margin-left:5px;" src="../images/permalink.png" |
| alt="" /></a></h2> |
| <div class="syntaxlink"><a href="sA.html#sA.3.2" title="§A.3.2 CalloutBinding" |
| class="syntax">→ Syntax §A.3.2</a></div> |
| <p>A role class may acquire the implementation for any of its |
| (expected) methods by declaring a <strong>callout</strong> binding. |
| |
| </p> |
| <div class="subsect depth3" id="s3.1.a"> |
| <h4 class="subsect">(a) <span class="title">Prerequisite: Class binding</span><a class="img" href="s3.1.a.html" |
| title="PermaLink to (a) Prerequisite: Class binding"><img style="vertical-align:text-top;margin-left:5px;" src="../images/permalink.png" |
| alt="" /></a></h4> |
| <p>A callout binding requires the enclosing class to be a role class |
| bound to a base class according to <a href="s2.1.html" title="§2.1 playedBy relation" class="sect">§2.1</a>. |
| |
| </p> |
| </div> |
| <div class="subsect depth3" id="s3.1.b"> |
| <h4 class="subsect">(b) <span class="title">Definition</span><a class="img" href="s3.1.b.html" title="PermaLink to (b) Definition"><img style="vertical-align:text-top;margin-left:5px;" src="../images/permalink.png" |
| alt="" /></a></h4> |
| <p>A callout binding maps an abstract role method ("expected method") |
| to a concrete base method ("provided method"). |
| It may appear within the role class at any place where feature |
| declarations are allowed. It is denoted by |
| |
| </p> |
| <div class="listing plain"><pre><i>expected_method_designator</i> <b>-></b> <i>provided_method_designator;</i></pre></div> |
| <p>The effect is that any call to the role method will be forwarded to the |
| associated base object using the provided base method. |
| |
| </p> |
| <h5 class="listing">Example code (Callout):</h5> |
| <div class="listing example frame"> |
| <table class="listing"> |
| <tr class="line odd"> |
| <td class="ln">1</td> |
| <td><pre><b>team</b> <b>class</b> Company {</pre></td> |
| </tr> |
| <tr class="line even"> |
| <td class="ln">2</td> |
| <td><pre> <b>public</b> <b>class</b> Employee <b>playedBy</b> Person {</pre></td> |
| </tr> |
| <tr class="line odd"> |
| <td class="ln">3</td> |
| <td><pre> <b>abstract</b> String getIdentification();</pre></td> |
| </tr> |
| <tr class="line even"> |
| <td class="ln">4</td> |
| <td><pre> <span class="comment">// callout binding see below...</span></pre></td> |
| </tr> |
| <tr class="line odd"> |
| <td class="ln">5</td> |
| <td><pre> }</pre></td> |
| </tr> |
| <tr class="line even"> |
| <td class="ln">6</td> |
| <td><pre>}</pre></td> |
| </tr> |
| </table> |
| </div> |
| </div> |
| <div class="subsect depth3" id="s3.1.c"> |
| <h4 class="subsect">(c) <span class="title">Kinds of method designators</span><a class="img" href="s3.1.c.html" |
| title="PermaLink to (c) Kinds of method designators"><img style="vertical-align:text-top;margin-left:5px;" src="../images/permalink.png" |
| alt="" /></a></h4> |
| <p>A method designator may either be a method name |
| |
| </p> |
| <div class="listing example frame"> |
| <table class="listing"> |
| <tr class="line odd"> |
| <td class="ln">4</td> |
| <td><pre>getIdentification <em>-></em> getName;</pre></td> |
| </tr> |
| </table> |
| </div> |
| <p><strong>or</strong> |
| a complete method signature including parameter declarations and |
| return type declaration, but excluding any modifiers and declared exceptions. |
| |
| </p> |
| <div class="listing example frame"> |
| <table class="listing"> |
| <tr class="line odd"> |
| <td class="ln">4</td> |
| <td><pre>String getIdentification() <em>-></em> String getName();</pre></td> |
| </tr> |
| </table> |
| </div> |
| <div class="codecomment"> |
| <h5>Effects:</h5> |
| <ul> |
| <li> Line 4 declares a callout binding for the role method <code>getIdentification()</code>, |
| providing an implementation for the abstract method defined in line 3. |
| </li> |
| <li> In combination with the role binding in line 2 this has the following effect:</li> |
| <li> Any call to <code>Employee.getIdentification</code> |
| is forwarded to the method <code>Person.getName</code>. |
| </li> |
| </ul> |
| </div> |
| <p>Both sides of a callout binding must use the same kind of |
| designators, i.e., designators with and without signature may not be mixed. |
| <br /> |
| Each method designator must uniquely select one method. |
| If a method designator contains a signature this signature must match exactly with the signature |
| of an existing method, i.e., no implicit conversions are applied for this matching. |
| If overloading is involved, signatures <em>must</em> be used to disambiguate. |
| |
| </p> |
| </div> |
| <div class="subsect depth3" id="s3.1.d"> |
| <h4 class="subsect">(d) <span class="title">Inheritance of role method declarations</span><a class="img" href="s3.1.d.html" |
| title="PermaLink to (d) Inheritance of role method declarations"><img style="vertical-align:text-top;margin-left:5px;" src="../images/permalink.png" |
| alt="" /></a></h4> |
| <p>The role method being bound by a callout may be declared in the same |
| class as the binding or it may be inherited from a super class or |
| super interface. |
| |
| </p> |
| </div> |
| <div class="subsect depth3" id="s3.1.e"> |
| <h4 class="subsect">(e) <span class="title">Callout override</span><a class="img" href="s3.1.e.html" title="PermaLink to (e) Callout override"><img style="vertical-align:text-top;margin-left:5px;" src="../images/permalink.png" |
| alt="" /></a></h4> |
| <p>If an inherited role method is concrete, callout binding regarding this |
| method must use the token "<code>=></code>" instead of "<code>-></code>" |
| in order to declare that this binding overrides an existing implementation. |
| <br /> |
| |
| Using the "<code>=></code>" operator for an abstract method is an error. |
| <br /> |
| It is also an error (and not useful anyway) to callout-bind a method that is |
| implemented in the same class as the binding. |
| |
| </p> |
| </div> |
| <div class="subsect depth3" id="s3.1.f"> |
| <h4 class="subsect">(f) <span class="title">Inheritance of callout bindings</span><a class="img" href="s3.1.f.html" |
| title="PermaLink to (f) Inheritance of callout bindings"><img style="vertical-align:text-top;margin-left:5px;" src="../images/permalink.png" |
| alt="" /></a></h4> |
| <p> Callout bindings are inherited along explicit and implicit inheritance. |
| Inherited callout bindings can be overridden using "<code>=></code>". |
| |
| </p> |
| </div> |
| <div class="subsect depth3" id="s3.1.g"> |
| <h4 class="subsect">(g) <span class="title">Duplicate bindings</span><a class="img" href="s3.1.g.html" |
| title="PermaLink to (g) Duplicate bindings"><img style="vertical-align:text-top;margin-left:5px;" src="../images/permalink.png" |
| alt="" /></a></h4> |
| <p>It is an error if a role class has multiple callout bindings for the |
| same role method. |
| |
| </p> |
| </div> |
| <div class="subsect depth3" id="s3.1.h"> |
| <h4 class="subsect">(h) <span class="title">Declared exceptions</span><a class="img" href="s3.1.h.html" |
| title="PermaLink to (h) Declared exceptions"><img style="vertical-align:text-top;margin-left:5px;" src="../images/permalink.png" |
| alt="" /></a></h4> |
| <p>It is an error if a base method to be bound by <strong>callout</strong> |
| declares in its <code>throws</code> clause any exceptions that |
| are not declared by the corresponding role method. |
| |
| </p> |
| </div> |
| <div class="subsect depth3" id="s3.1.i"> |
| <h4 class="subsect">(i) <span class="title">Shorthand definition</span><a class="img" href="s3.1.i.html" |
| title="PermaLink to (i) Shorthand definition"><img style="vertical-align:text-top;margin-left:5px;" src="../images/permalink.png" |
| alt="" /></a></h4> |
| <p> A callout binding whose method designators specify |
| full method signatures does not require an existing role method. |
| If no role method is found matching the expected method of |
| such a callout binding, a new method is implicitly generated. |
| The new method is static iff the bound base method is static, |
| and it declares the same exceptions as the bound base method. |
| |
| </p> |
| <p> |
| A shorthand callout may optionally declare a <strong>visibility modifier</strong>, |
| otherwise the generated method inherits the visibility modifier of the bound base method. |
| No further modifiers are set. |
| If a callout overrides an inherited method or callout, |
| it must not reduce the visibility of the inherited method/callout. |
| |
| </p> |
| </div> |
| <div class="subsect depth3" id="s3.1.j"> |
| <h4 class="subsect">(j) <span class="title">Inferred callout</span><a class="img" href="s3.1.j.html" title="PermaLink to (j) Inferred callout"><img style="vertical-align:text-top;margin-left:5px;" src="../images/permalink.png" |
| alt="" /></a></h4> |
| <p> If a non-abstract role class inherits an abstract method the compiler |
| tries to infer a callout binding for implementing the abstract method. |
| Similarly, if a self-call in a role class cannot be resolved, the compiler |
| tries to infer a callout to resolve the self-call.<br /> |
| Inference searches for a method in the bound base class such that |
| |
| </p> |
| <ol> |
| <li>both methods have the same name</li> |
| <li>both methods have the same number of arguments</li> |
| <li>each argument of the abstract role method is compatible to the |
| corresponding argument of the base method directly, or using |
| boxing/unboxing or lowering. |
| </li> |
| </ol> |
| <p> |
| Callouts inferred from an interface have <code>public</code> visibility, |
| callouts inferred from a self-call have <code>private</code> visibility. |
| |
| </p> |
| <p> |
| Per default inferred callout bindings are disabled, i.e., a compiler |
| must report these as an error. However, a compiler should allow to |
| configure reporting to produce a warning only (which can be suppressed |
| using a <code>@SuppressWarnings("inferredcallout")</code> annotation), |
| or to completely ignore the diagnostic. |
| |
| </p> |
| </div> |
| <div class="subsect depth3" id="s3.1.k"> |
| <h4 class="subsect">(k) <span class="title">Callout to generic method</span><a class="img" href="s3.1.k.html" |
| title="PermaLink to (k) Callout to generic method"><img style="vertical-align:text-top;margin-left:5px;" src="../images/permalink.png" |
| alt="" /></a></h4> |
| <p>When referring to a generic base method</p> |
| <div class="listing example frame"> |
| <table class="listing"> |
| <tr class="line odd"> |
| <td class="ln">1</td> |
| <td><pre><T> T bm(T a)</pre></td> |
| </tr> |
| </table> |
| </div> |
| <p>a callout binding may either propagate the method's genericity as in</p> |
| <div class="listing example frame"> |
| <table class="listing"> |
| <tr class="line odd"> |
| <td class="ln">2</td> |
| <td><pre><T> T rm(T a) <b>-></b> T bm(T a);</pre></td> |
| </tr> |
| </table> |
| </div> |
| <p>or it may supply a valid substitution for the type parameter as in</p> |
| <div class="listing example frame"> |
| <table class="listing"> |
| <tr class="line odd"> |
| <td class="ln">2</td> |
| <td><pre>String rm(String a) <b>-></b> String bm(String a);</pre></td> |
| </tr> |
| </table> |
| </div> |
| </div> |
| <p>A callout binding either attaches an implementation to a previously declared method |
| or adds (<a href="#s3.1.i" title="§3.1.(i) Shorthand definition" class="sect">§3.1.(i)</a> above) a forwarding method to a role class. |
| Apart from this implementation, callout-bound methods do not differ from regular methods. |
| |
| </p> |
| <p>When we say, a callout binding defines <strong>forwarding</strong> this means that |
| control is passed to the base object. In contrast, by a <strong>delegation</strong> |
| semantics control <em>would</em> remain at the role object, such that self-calls |
| would again be dispatched starting at the role. Callout bindings on |
| their own do not support delegation. However, in conjunction with method |
| overriding by means of callin bindings (see <a href="s4.html" title="§4 Callin Binding" class="sect">§4</a>) |
| the effect of delegation can easily be achieved. |
| |
| </p> |
| </div> |
| <table class="nav"> |
| <tr> |
| <td class="back"></td> |
| <td class="top"><a href="index.html" rel="contents">↑ Table of Contents ↑</a></td> |
| <td class="next"><a href="s3.2.html" rel="next">§3.2 Callout parameter mapping >></a></td> |
| </tr> |
| </table> |
| <div class="breadcrumb"><a class="nav" href="s3.html" rel="section">§3 Callout Binding</a></div> |
| </div> |
| <div id="footer"> |
| <hr /><a class="w3c img" href="http://jigsaw.w3.org/css-validator/check/referer" |
| shape="rect"><img src="../images/valid-css2-blue.png" alt="Valid CSS!" height="31" width="88" /></a><a class="w3c img" href="http://validator.w3.org/check?uri=referer" shape="rect"><img src="../images/valid-xhtml10-blue.png" alt="Valid XHTML 1.0 Strict" height="31" |
| width="88" /></a><address>© Stephan Herrmann, Christine Hundt, Marco Mosconi</address> |
| OT/J version 1.3 — last modified: 2010-05-18 |
| </div> |
| </body> |
| </html> |