blob: 010a673cfcc6ca8e5692c0754472fa76c23c94e5 [file] [log] [blame]
Stephan Herrmann01664412010-04-01 20:28:43 +00001<!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 Herrmann01664412010-04-01 20:28:43 +00006 <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">&lt;&lt;&nbsp;&sect;4.7&nbsp;Callin binding with static methods</a></td>
15 <td class="top"><a href="index.html" rel="contents">&uarr;&nbsp;Table of Contents&nbsp;&uarr;</a></td>
16 <td class="next"><a href="s4.9.html" rel="next">&sect;4.9&nbsp;Callin inheritance&nbsp;&gt;&gt;</a></td>
17 </tr>
18 </table>
19 <div class="breadcrumb"><a class="nav" href="s4.html" rel="section">&sect;4&nbsp;Callin Binding</a></div>
20 <div class="sect depth2" id="s4.8">
Stephan Herrmann109893e2010-05-18 22:02:53 +000021 <h2 class="sect">&sect;4.8&nbsp;Callin precedence<a class="img" href="s4.8.html"
22 title="PermaLink to &sect;4.8&nbsp;Callin precedence"><img style="vertical-align:text-top;margin-left:5px;" src="../images/permalink.png"
23 alt="" /></a></h2>
Stephan Herrmann01664412010-04-01 20:28:43 +000024 <div class="syntaxlink"><a href="sA.8.html" title="&sect;A.8&nbsp;Precedence declaration"
25 class="syntax">&rarr;&nbsp;Syntax&nbsp;&sect;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 Herrmann109893e2010-05-18 22:02:53 +000032 <h4 class="subsect">(a)&nbsp;<span class="title">Precedence declaration</span><a class="img" href="s4.8.a.html"
33 title="PermaLink to (a)&nbsp;Precedence declaration"><img style="vertical-align:text-top;margin-left:5px;" src="../images/permalink.png"
34 alt="" /></a></h4>
Stephan Herrmann01664412010-04-01 20:28:43 +000035 <p>A precedence declaration consists of the keyword <code>precedence</code> followed by
Stephan Herrmann109893e2010-05-18 22:02:53 +000036 a list of names referring to callin bindings (see <a href="s4.1.e.html" title="&sect;4.1.(e)&nbsp;Named callin binding"
Stephan Herrmann01664412010-04-01 20:28:43 +000037 class="sect">&sect;4.1.(e)</a> for named callin bindings).
Stephan Herrmann109893e2010-05-18 22:02:53 +000038
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="&sect;5.1&nbsp;Effect of team activation"
45 class="sect">&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="&sect;4.8.(c)&nbsp;Class based precedence"
49 class="sect">&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 Herrmann01664412010-04-01 20:28:43 +000052
53 </p>
Stephan Herrmann109893e2010-05-18 22:02:53 +000054 <div class="listing plain"><pre><b>precedence</b> <b>after</b> importantExecuteLast, lessImportantExecuteEarlier;</pre></div>
Stephan Herrmann01664412010-04-01 20:28:43 +000055 </div>
56 <div class="subsect depth3" id="s4.8.b">
Stephan Herrmann109893e2010-05-18 22:02:53 +000057 <h4 class="subsect">(b)&nbsp;<span class="title">Qualified and unqualified names</span><a class="img" href="s4.8.b.html"
58 title="PermaLink to (b)&nbsp;Qualified and unqualified names"><img style="vertical-align:text-top;margin-left:5px;" src="../images/permalink.png"
59 alt="" /></a></h4>
Stephan Herrmann01664412010-04-01 20:28:43 +000060 <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="&sect;1.3.1&nbsp;Acquisition and implicit inheritance of role classes"
69 class="sect">&sect;1.3.1</a>).
70
71 </p>
72 </div>
73 <div class="subsect depth3" id="s4.8.c">
Stephan Herrmann109893e2010-05-18 22:02:53 +000074 <h4 class="subsect">(c)&nbsp;<span class="title">Class based precedence</span><a class="img" href="s4.8.c.html"
75 title="PermaLink to (c)&nbsp;Class based precedence"><img style="vertical-align:text-top;margin-left:5px;" src="../images/permalink.png"
76 alt="" /></a></h4>
Stephan Herrmann01664412010-04-01 20:28:43 +000077 <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 Herrmann109893e2010-05-18 22:02:53 +000083 <h4 class="subsect">(d)&nbsp;<span class="title">Multiple precedence statements</span><a class="img" href="s4.8.d.html"
84 title="PermaLink to (d)&nbsp;Multiple precedence statements"><img style="vertical-align:text-top;margin-left:5px;" src="../images/permalink.png"
85 alt="" /></a></h4>
Stephan Herrmann01664412010-04-01 20:28:43 +000086 <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 Herrmann8f0fa312010-06-08 18:24:55 +000088 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 Herrmann01664412010-04-01 20:28:43 +000098 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 Herrmann109893e2010-05-18 22:02:53 +0000103 <h4 class="subsect">(e)&nbsp;<span class="title">Binding overriding</span><a class="img" href="s4.8.e.html"
104 title="PermaLink to (e)&nbsp;Binding overriding"><img style="vertical-align:text-top;margin-left:5px;" src="../images/permalink.png"
105 alt="" /></a></h4>
Stephan Herrmann01664412010-04-01 20:28:43 +0000106 <p>Precedence declarations may conflict with overriding of callin bindings
Stephan Herrmann109893e2010-05-18 22:02:53 +0000107 (see <a href="s4.1.e.html" title="&sect;4.1.(e)&nbsp;Named callin binding"
Stephan Herrmann01664412010-04-01 20:28:43 +0000108 class="sect">&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>&lt;-</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>&lt;-</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="&sect;5&nbsp;Team Activation" class="sect">&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">&lt;&lt;&nbsp;&sect;4.7&nbsp;Callin binding with static methods</a></td>
193 <td class="top"><a href="index.html" rel="contents">&uarr;&nbsp;Table of Contents&nbsp;&uarr;</a></td>
194 <td class="next"><a href="s4.9.html" rel="next">&sect;4.9&nbsp;Callin inheritance&nbsp;&gt;&gt;</a></td>
195 </tr>
196 </table>
197 <div class="breadcrumb"><a class="nav" href="s4.html" rel="section">&sect;4&nbsp;Callin Binding</a></div>
198 </div>
199 <div id="footer">
Stephan Herrmann109893e2010-05-18 22:02:53 +0000200 <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>&copy; Stephan Herrmann, Christine Hundt, Marco Mosconi</address>
Stephan Herrmann8f0fa312010-06-08 18:24:55 +0000203 OT/J version 1.3 &mdash; last modified: 2010-06-08
Stephan Herrmann01664412010-04-01 20:28:43 +0000204 </div>
205 </body>
206</html>