Stephan Herrmann | 0166441 | 2010-04-01 20:28:43 +0000 | [diff] [blame] | 1 | <!DOCTYPE html |
| 2 | PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "../xhtml1-strict.dtd"> |
| 3 | <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> |
| 4 | <head> |
| 5 | <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> |
Stephan Herrmann | 0166441 | 2010-04-01 20:28:43 +0000 | [diff] [blame] | 6 | <link rel="stylesheet" type="text/css" href="../css/ot.css" /> |
| 7 | <link rel="stylesheet" type="text/css" href="../css/otjld.css" /> |
| 8 | <title>OT/J Language Definition v1.3</title> |
| 9 | </head> |
| 10 | <body class="otdt"> |
| 11 | <div id="content"> |
| 12 | <table class="nav"> |
| 13 | <tr> |
| 14 | <td class="back"><a id="top"></a><a href="s4.7.html" rel="prev"><< §4.7 Callin binding with static methods</a></td> |
| 15 | <td class="top"><a href="index.html" rel="contents">↑ Table of Contents ↑</a></td> |
| 16 | <td class="next"><a href="s4.9.html" rel="next">§4.9 Callin inheritance >></a></td> |
| 17 | </tr> |
| 18 | </table> |
| 19 | <div class="breadcrumb"><a class="nav" href="s4.html" rel="section">§4 Callin Binding</a></div> |
| 20 | <div class="sect depth2" id="s4.8"> |
Stephan Herrmann | 109893e | 2010-05-18 22:02:53 +0000 | [diff] [blame] | 21 | <h2 class="sect">§4.8 Callin precedence<a class="img" href="s4.8.html" |
| 22 | title="PermaLink to §4.8 Callin precedence"><img style="vertical-align:text-top;margin-left:5px;" src="../images/permalink.png" |
| 23 | alt="" /></a></h2> |
Stephan Herrmann | 0166441 | 2010-04-01 20:28:43 +0000 | [diff] [blame] | 24 | <div class="syntaxlink"><a href="sA.8.html" title="§A.8 Precedence declaration" |
| 25 | class="syntax">→ Syntax §A.8</a></div> |
| 26 | <p>If multiple callins from the same team refer to the same base method and also have the same |
| 27 | callin modifier (<code>before</code>, <code>after</code> or <code>replace</code>), the order in which |
| 28 | the callin bindings shall be triggered has to be declared using a precedence declaration. |
| 29 | |
| 30 | </p> |
| 31 | <div class="subsect depth3" id="s4.8.a"> |
Stephan Herrmann | 109893e | 2010-05-18 22:02:53 +0000 | [diff] [blame] | 32 | <h4 class="subsect">(a) <span class="title">Precedence declaration</span><a class="img" href="s4.8.a.html" |
| 33 | title="PermaLink to (a) Precedence declaration"><img style="vertical-align:text-top;margin-left:5px;" src="../images/permalink.png" |
| 34 | alt="" /></a></h4> |
Stephan Herrmann | 0166441 | 2010-04-01 20:28:43 +0000 | [diff] [blame] | 35 | <p>A precedence declaration consists of the keyword <code>precedence</code> followed by |
Stephan Herrmann | 109893e | 2010-05-18 22:02:53 +0000 | [diff] [blame] | 36 | a list of names referring to callin bindings (see <a href="s4.1.e.html" title="§4.1.(e) Named callin binding" |
Stephan Herrmann | 0166441 | 2010-04-01 20:28:43 +0000 | [diff] [blame] | 37 | class="sect">§4.1.(e)</a> for named callin bindings). |
Stephan Herrmann | 109893e | 2010-05-18 22:02:53 +0000 | [diff] [blame] | 38 | |
| 39 | </p> |
| 40 | <div class="listing plain"><pre><b>precedence</b> callinBinding1, callinBinding2;</pre></div> |
| 41 | <p> |
| 42 | A precedence declaration is only legal within a role or team class.<br /> |
| 43 | The order of elements in a precedence declaration determines their <strong>priority</strong> during dispatch, |
| 44 | similar to priorities based on activation of several team instances (<a href="s5.1.html" title="§5.1 Effect of team activation" |
| 45 | class="sect">§5.1</a>). |
| 46 | This means that <code>before</code> and <code>replace</code> binding with highest priority trigger first, |
| 47 | whereas <code>after</code> bindings with highest priority trigger last. |
| 48 | For binding precedences (as opposed to class based precedence, see <a href="#s4.8.c" title="§4.8.(c) Class based precedence" |
| 49 | class="sect">§4.8.(c)</a> below) |
| 50 | which refer to <code>after</code> bindings, the precedence declaration must also use the <code>after</code> keyword |
| 51 | to remind the programmer that the execution order is inverse to the textual order. |
Stephan Herrmann | 0166441 | 2010-04-01 20:28:43 +0000 | [diff] [blame] | 52 | |
| 53 | </p> |
Stephan Herrmann | 109893e | 2010-05-18 22:02:53 +0000 | [diff] [blame] | 54 | <div class="listing plain"><pre><b>precedence</b> <b>after</b> importantExecuteLast, lessImportantExecuteEarlier;</pre></div> |
Stephan Herrmann | 0166441 | 2010-04-01 20:28:43 +0000 | [diff] [blame] | 55 | </div> |
| 56 | <div class="subsect depth3" id="s4.8.b"> |
Stephan Herrmann | 109893e | 2010-05-18 22:02:53 +0000 | [diff] [blame] | 57 | <h4 class="subsect">(b) <span class="title">Qualified and unqualified names</span><a class="img" href="s4.8.b.html" |
| 58 | title="PermaLink to (b) Qualified and unqualified names"><img style="vertical-align:text-top;margin-left:5px;" src="../images/permalink.png" |
| 59 | alt="" /></a></h4> |
Stephan Herrmann | 0166441 | 2010-04-01 20:28:43 +0000 | [diff] [blame] | 60 | <p>Within a role class a callin binding may be referenced by its unqualified name. |
| 61 | A precedence declaration in a team class must qualify the callin name with the name of the declaring |
| 62 | role class. A team with nested teams may concat role class names. |
| 63 | Elements of a qualified callin name are separated by ".". |
| 64 | <br /> |
| 65 | The callin binding must be found in the role specified by the qualifying prefix or |
| 66 | in the enclosing role for unqualified names, or any super class of this role |
| 67 | (including implicit super classes <a href="s1.3.1.html" |
| 68 | title="§1.3.1 Acquisition and implicit inheritance of role classes" |
| 69 | class="sect">§1.3.1</a>). |
| 70 | |
| 71 | </p> |
| 72 | </div> |
| 73 | <div class="subsect depth3" id="s4.8.c"> |
Stephan Herrmann | 109893e | 2010-05-18 22:02:53 +0000 | [diff] [blame] | 74 | <h4 class="subsect">(c) <span class="title">Class based precedence</span><a class="img" href="s4.8.c.html" |
| 75 | title="PermaLink to (c) Class based precedence"><img style="vertical-align:text-top;margin-left:5px;" src="../images/permalink.png" |
| 76 | alt="" /></a></h4> |
Stephan Herrmann | 0166441 | 2010-04-01 20:28:43 +0000 | [diff] [blame] | 77 | <p>At the team level a precedence declaration may contain role class names without |
| 78 | explicitly mentioning callin bindings in order to refer to all callin bindings of the role. |
| 79 | |
| 80 | </p> |
| 81 | </div> |
| 82 | <div class="subsect depth3" id="s4.8.d"> |
Stephan Herrmann | 109893e | 2010-05-18 22:02:53 +0000 | [diff] [blame] | 83 | <h4 class="subsect">(d) <span class="title">Multiple precedence statements</span><a class="img" href="s4.8.d.html" |
| 84 | title="PermaLink to (d) Multiple precedence statements"><img style="vertical-align:text-top;margin-left:5px;" src="../images/permalink.png" |
| 85 | alt="" /></a></h4> |
Stephan Herrmann | 0166441 | 2010-04-01 20:28:43 +0000 | [diff] [blame] | 86 | <p>All precedence statements are collected at the outer-most team. At that level all |
| 87 | precedence declarations involving the same base method are merged using the |
Stephan Herrmann | 8f0fa31 | 2010-06-08 18:24:55 +0000 | [diff] [blame^] | 88 | C3 algorithm <a href="s4.html#fn3-c3-algorithm" class="int">[3]</a>. |
| 89 | When merging precendence declarations more deeply nested declarations have higher priority |
| 90 | than outer declarations. |
| 91 | For several declarations at the same nesting level the lexical ordering determines the priority. |
| 92 | |
| 93 | </p> |
| 94 | <p> |
| 95 | At any point the C3 algorithm will ensure that the resulting order after merging is consistent |
| 96 | with each individual precedence declaration. |
| 97 | It is an error to declare |
Stephan Herrmann | 0166441 | 2010-04-01 20:28:43 +0000 | [diff] [blame] | 98 | incompatible precedence lists that cannot be merged by the C3 algorithm. |
| 99 | |
| 100 | </p> |
| 101 | </div> |
| 102 | <div class="subsect depth3" id="s4.8.e"> |
Stephan Herrmann | 109893e | 2010-05-18 22:02:53 +0000 | [diff] [blame] | 103 | <h4 class="subsect">(e) <span class="title">Binding overriding</span><a class="img" href="s4.8.e.html" |
| 104 | title="PermaLink to (e) Binding overriding"><img style="vertical-align:text-top;margin-left:5px;" src="../images/permalink.png" |
| 105 | alt="" /></a></h4> |
Stephan Herrmann | 0166441 | 2010-04-01 20:28:43 +0000 | [diff] [blame] | 106 | <p>Precedence declarations may conflict with overriding of callin bindings |
Stephan Herrmann | 109893e | 2010-05-18 22:02:53 +0000 | [diff] [blame] | 107 | (see <a href="s4.1.e.html" title="§4.1.(e) Named callin binding" |
Stephan Herrmann | 0166441 | 2010-04-01 20:28:43 +0000 | [diff] [blame] | 108 | class="sect">§4.1.(e)</a>): For each pair of callin bindings of which one |
| 109 | callin binding overrides the other one, precedence declarations are not applicable, |
| 110 | since dynamic binding will already select exactly one callin binding. |
| 111 | <br /> |
| 112 | It is an error to <i>explicitly mention</i> such a pair of overriding callin bindings in a precedence declaration. |
| 113 | <br /> |
| 114 | When a class-based precedence declaration <i>implicitly refers to</i> a callin binding that is overridden by, |
| 115 | or overrides any other callin binding within the same precedence declaration, this does not affect the fact, |
| 116 | that the most specific callin binding overrides less specific ones. |
| 117 | |
| 118 | </p> |
| 119 | </div> |
| 120 | <h5 class="listing">Callin binding example</h5> |
| 121 | <div class="listing example frame"> |
| 122 | <table class="listing"> |
| 123 | <tr class="line odd"> |
| 124 | <td class="ln">1</td> |
| 125 | <td><pre><b>public</b> <b>class</b> LogLog<b>in</b> <b>playedBy</b> Data<b>base</b> {</pre></td> |
| 126 | </tr> |
| 127 | <tr class="line even"> |
| 128 | <td class="ln">2</td> |
| 129 | <td><pre> <b>callin</b> <b>void</b> log (String what) {</pre></td> |
| 130 | </tr> |
| 131 | <tr class="line odd"> |
| 132 | <td class="ln">3</td> |
| 133 | <td><pre> System.out.println("enter " + what);</pre></td> |
| 134 | </tr> |
| 135 | <tr class="line even"> |
| 136 | <td class="ln">4</td> |
| 137 | <td><pre> base.log(what.toLowerCase());</pre></td> |
| 138 | </tr> |
| 139 | <tr class="line odd"> |
| 140 | <td class="ln">5</td> |
| 141 | <td><pre> System.out.println("leave " + what);</pre></td> |
| 142 | </tr> |
| 143 | <tr class="line even"> |
| 144 | <td class="ln">6</td> |
| 145 | <td><pre> }</pre></td> |
| 146 | </tr> |
| 147 | <tr class="line odd"> |
| 148 | <td class="ln">7</td> |
| 149 | <td><pre> <b>void</b> log(String what) <b><-</b> <b>replace</b> <b>void</b> login(String uid, String passwd) </pre></td> |
| 150 | </tr> |
| 151 | <tr class="line even"> |
| 152 | <td class="ln">8</td> |
| 153 | <td><pre> <b>with</b> { what <b><-</b> uid }</pre></td> |
| 154 | </tr> |
| 155 | <tr class="line odd"> |
| 156 | <td class="ln">9</td> |
| 157 | <td><pre>}</pre></td> |
| 158 | </tr> |
| 159 | <tr class="line even"> |
| 160 | <td class="ln">10</td> |
| 161 | <td><pre>(<b>new</b> Database()).login("Admin", "Passwd");</pre></td> |
| 162 | </tr> |
| 163 | </table> |
| 164 | </div> |
| 165 | <div class="codecomment"> |
| 166 | <h5>Effects:</h5> |
| 167 | <p>Provided the callin bindings are active (cf. <a href="s5.html" title="§5 Team Activation" class="sect">§5</a>) then: |
| 168 | |
| 169 | </p> |
| 170 | <ul> |
| 171 | <li>the call in line 10 is intercepted by method <code>log</code> |
| 172 | of role <code>LogLogin</code>. |
| 173 | </li> |
| 174 | <li>the call target of <code>log</code> is a role of type |
| 175 | <code>LogLogin</code> which is created by lifting the |
| 176 | original call target (of type <code>Database</code>) to |
| 177 | <code>LogLogin</code>. |
| 178 | </li> |
| 179 | <li>only parameter <code>uid</code> is passed to <code>log</code> |
| 180 | (bound to formal parameter <code>what</code>). |
| 181 | </li> |
| 182 | <li>within method <code>log</code> the base call (line 4) invokes |
| 183 | the original method passing a modified uid (converted to lower case, cf. line 4) |
| 184 | and the unmodified password, which is hidden from the callin method due to the |
| 185 | parameter mapping in line 8. |
| 186 | </li> |
| 187 | </ul> |
| 188 | </div> |
| 189 | </div> |
| 190 | <table class="nav"> |
| 191 | <tr> |
| 192 | <td class="back"><a href="s4.7.html" rel="prev"><< §4.7 Callin binding with static methods</a></td> |
| 193 | <td class="top"><a href="index.html" rel="contents">↑ Table of Contents ↑</a></td> |
| 194 | <td class="next"><a href="s4.9.html" rel="next">§4.9 Callin inheritance >></a></td> |
| 195 | </tr> |
| 196 | </table> |
| 197 | <div class="breadcrumb"><a class="nav" href="s4.html" rel="section">§4 Callin Binding</a></div> |
| 198 | </div> |
| 199 | <div id="footer"> |
Stephan Herrmann | 109893e | 2010-05-18 22:02:53 +0000 | [diff] [blame] | 200 | <hr /><a class="w3c img" href="http://jigsaw.w3.org/css-validator/check/referer" |
| 201 | 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" |
| 202 | width="88" /></a><address>© Stephan Herrmann, Christine Hundt, Marco Mosconi</address> |
Stephan Herrmann | 8f0fa31 | 2010-06-08 18:24:55 +0000 | [diff] [blame^] | 203 | OT/J version 1.3 — last modified: 2010-06-08 |
Stephan Herrmann | 0166441 | 2010-04-01 20:28:43 +0000 | [diff] [blame] | 204 | </div> |
| 205 | </body> |
| 206 | </html> |