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="s3.3.html" rel="prev"><< §3.3 Lifting and lowering</a></td> |
| 15 | <td class="top"><a href="index.html" rel="contents">↑ Table of Contents ↑</a></td> |
| 16 | <td class="next"><a href="s3.5.html" rel="next">§3.5 Callout to field >></a></td> |
| 17 | </tr> |
| 18 | </table> |
| 19 | <div class="breadcrumb"><a class="nav" href="s3.html" rel="section">§3 Callout Binding</a></div> |
| 20 | <div class="sect depth2" id="s3.4"> |
Stephan Herrmann | 109893e | 2010-05-18 22:02:53 +0000 | [diff] [blame] | 21 | <h2 class="sect">§3.4 Overriding access restrictions<a class="img" href="s3.4.html" |
| 22 | title="PermaLink to §3.4 Overriding access restrictions"><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 | <p>In contrast to normal access restrictions, method bindings |
| 25 | may refer to hidden base methods. |
| 26 | This concept is the inverse of encapsulation, hence it is called |
| 27 | <strong>decapsulation</strong>. |
| 28 | <br /> |
| 29 | Decapsulation may occur in these positions: |
| 30 | |
| 31 | </p> |
| 32 | <ul> |
| 33 | <li><code>playedBy</code> declaration (see <a href="s2.1.2.c.html" title="§2.1.2.(c) Base class decapsulation" |
| 34 | class="sect">§2.1.2.(c)</a>) |
| 35 | </li> |
| 36 | <li>base constructor call (see <a href="s2.4.2.b.html" title="§2.4.2.(b) Bound roles" class="sect">§2.4.2.(b)</a>). |
| 37 | </li> |
| 38 | <li>callout bindings (see next)</li> |
| 39 | <li>callout to field (see <a href="s3.5.e.html" title="§3.5.(e) Access control" class="sect">§3.5.(e)</a>) |
| 40 | </li> |
| 41 | <li>base call within a callin method (see <a href="s4.6.html" title="§4.6 Overriding access restrictions" |
| 42 | class="sect">§4.6</a>) |
| 43 | </li> |
| 44 | </ul> |
| 45 | <div class="subsect depth3" id="s3.4.a"> |
Stephan Herrmann | 109893e | 2010-05-18 22:02:53 +0000 | [diff] [blame] | 46 | <h4 class="subsect">(a) <span class="title">Callout to inaccessible base method</span><a class="img" href="s3.4.a.html" |
| 47 | title="PermaLink to (a) Callout to inaccessible base method"><img style="vertical-align:text-top;margin-left:5px;" src="../images/permalink.png" |
| 48 | alt="" /></a></h4> |
Stephan Herrmann | 0166441 | 2010-04-01 20:28:43 +0000 | [diff] [blame] | 49 | <p>By means of <strong>callout</strong> bindings it is possible to access |
| 50 | methods of a base class regardless of their access modifiers. |
| 51 | Method bindings are the only place in a program which may mention otherwise |
| 52 | inaccessible methods. |
| 53 | Access to the callout method at the role side is controlled by regular mechanisms, |
| 54 | based on the declaration of the role method. |
| 55 | |
| 56 | </p> |
| 57 | </div> |
| 58 | <div class="subsect depth3" id="s3.4.b"> |
Stephan Herrmann | 109893e | 2010-05-18 22:02:53 +0000 | [diff] [blame] | 59 | <h4 class="subsect">(b) <span class="title">Sealing against decapsulation</span><a class="img" href="s3.4.b.html" |
| 60 | title="PermaLink to (b) Sealing against decapsulation"><img style="vertical-align:text-top;margin-left:5px;" src="../images/permalink.png" |
| 61 | alt="" /></a></h4> |
Stephan Herrmann | 0166441 | 2010-04-01 20:28:43 +0000 | [diff] [blame] | 62 | <p>A base package may be "sealed" which re-establishes the standard Java visibility rules. |
| 63 | <br /> |
| 64 | Sealing is achieved by the corresponding capability of Jar files. |
| 65 | |
| 66 | </p> |
| 67 | </div> |
| 68 | <div class="subsect depth3" id="s3.4.c"> |
Stephan Herrmann | 109893e | 2010-05-18 22:02:53 +0000 | [diff] [blame] | 69 | <h4 class="subsect">(c) <span class="title">Warning levels</span><a class="img" href="s3.4.c.html" title="PermaLink to (c) Warning levels"><img style="vertical-align:text-top;margin-left:5px;" src="../images/permalink.png" |
| 70 | alt="" /></a></h4> |
Stephan Herrmann | 0166441 | 2010-04-01 20:28:43 +0000 | [diff] [blame] | 71 | <p>A compiler should signal any occurrence of decapsulation. |
| 72 | If a compiler supports to configure warnings this may be used to let the user choose to |
| 73 | (a) ignore base class decapsulation, (b) treat it as a warning or even |
| 74 | (c) treat it as an error (cf. <a href="s2.1.2.c.html" title="§2.1.2.(c) Base class decapsulation" |
| 75 | class="sect">§2.1.2.(c)</a>). |
| 76 | <br /> |
| 77 | Optionally, a batch compiler may support three levels of verbosity with respect to decapsulation: |
| 78 | |
| 79 | </p> |
| 80 | <table border="1"> |
| 81 | <tr> |
| 82 | <td rowspan="1" colspan="1"><tt>-nodecapsulation</tt></td> |
| 83 | <td rowspan="1" colspan="1">No warnings.</td> |
| 84 | </tr> |
| 85 | <tr> |
| 86 | <td rowspan="1" colspan="1"><em>default</em></td> |
| 87 | <td rowspan="1" colspan="1">Warn only if/that access restrictions are overridden.</td> |
| 88 | </tr> |
| 89 | <tr> |
| 90 | <td rowspan="1" colspan="1"><tt>-decapsulation</tt></td> |
| 91 | <td rowspan="1" colspan="1">Detailed messages containing the binding and the hidden base method.</td> |
| 92 | </tr> |
| 93 | </table> |
| 94 | </div> |
| 95 | <div class="subsect depth3" id="s3.4.d"> |
Stephan Herrmann | 109893e | 2010-05-18 22:02:53 +0000 | [diff] [blame] | 96 | <h4 class="subsect">(d) <span class="title">Private methods from super classes</span><a class="img" href="s3.4.d.html" |
| 97 | title="PermaLink to (d) Private methods from super classes"><img style="vertical-align:text-top;margin-left:5px;" src="../images/permalink.png" |
| 98 | alt="" /></a></h4> |
Stephan Herrmann | 0166441 | 2010-04-01 20:28:43 +0000 | [diff] [blame] | 99 | <p>If a callout binding shall bind to a private base method, that method |
| 100 | must be defined in the exact base class to which the current role |
| 101 | class is bound using <code>playedBy</code>. I.e., for private methods |
| 102 | <a href="s3.1.d.html" |
| 103 | title="§3.1.(d) Inheritance of role method declarations" |
| 104 | class="sect">§3.1.(d)</a> does not hold. |
| 105 | <br /> |
| 106 | The same holds for private base fields (see below). |
| 107 | <br /> |
| 108 | If a private base feature must indeed be callout-bound, a role class |
| 109 | must be defined that is played by the exact base class defining the |
| 110 | private feature. Another role bound to a sub-base-class can then |
| 111 | be defined as a sub class of the first role. It will inherit the |
| 112 | callout binding and through this it can access the desired feature. |
| 113 | |
| 114 | </p> |
| 115 | <div class="listing example frame"> |
| 116 | <table class="listing"> |
| 117 | <tr class="line odd"> |
| 118 | <td class="ln">1</td> |
| 119 | <td><pre><b>public</b> <b>class</b> SuperBase {</pre></td> |
| 120 | </tr> |
| 121 | <tr class="line even"> |
| 122 | <td class="ln">2</td> |
| 123 | <td><pre> <em><b>private</b> <b>int</b> secret;</em></pre></td> |
| 124 | </tr> |
| 125 | <tr class="line odd"> |
| 126 | <td class="ln">3</td> |
| 127 | <td><pre>}</pre></td> |
| 128 | </tr> |
| 129 | <tr class="line even"> |
| 130 | <td class="ln">4</td> |
| 131 | <td><pre><b>public</b> <b>class</b> SubBase <b>extends</b> SuperBase { <span class="comment">/* details omitted */</span> }</pre></td> |
| 132 | </tr> |
| 133 | <tr class="line odd"> |
| 134 | <td class="ln">5</td> |
| 135 | <td><pre><b>public</b> <b>team</b> <b>class</b> MyTeam {</pre></td> |
| 136 | </tr> |
| 137 | <tr class="line even"> |
| 138 | <td class="ln">6</td> |
| 139 | <td><pre> <b>protected</b> <b>class</b> SuperRole <b>playedBy</b> SuperBase {</pre></td> |
| 140 | </tr> |
| 141 | <tr class="line odd"> |
| 142 | <td class="ln">7</td> |
| 143 | <td><pre> <b>int</b> steal() <b>-></b> <b>get</b> <b>int</b> <em>secret</em>; <span class="comment">// <span class="green"><strong>OK</strong></span></span></pre></td> |
| 144 | </tr> |
| 145 | <tr class="line even"> |
| 146 | <td class="ln">8</td> |
| 147 | <td><pre> }</pre></td> |
| 148 | </tr> |
| 149 | <tr class="line odd"> |
| 150 | <td class="ln">9</td> |
| 151 | <td><pre> <b>protected</b> <b>class</b> SubRole <b>extends</b> SuperRole <b>playedBy</b> SubBase {</pre></td> |
| 152 | </tr> |
| 153 | <tr class="line even"> |
| 154 | <td class="ln">10</td> |
| 155 | <td><pre> <b>int</b> steal() <b>-></b> <b>get</b> <b>int</b> <em>secret</em>; <span class="comment">// <span class="error"><strong>illegal!</strong></span></span></pre></td> |
| 156 | </tr> |
| 157 | <tr class="line odd"> |
| 158 | <td class="ln">11</td> |
| 159 | <td><pre> }</pre></td> |
| 160 | </tr> |
| 161 | <tr class="line even"> |
| 162 | <td class="ln">12</td> |
| 163 | <td><pre>}</pre></td> |
| 164 | </tr> |
| 165 | </table> |
| 166 | </div> |
| 167 | </div> |
| 168 | </div> |
| 169 | <table class="nav"> |
| 170 | <tr> |
| 171 | <td class="back"><a href="s3.3.html" rel="prev"><< §3.3 Lifting and lowering</a></td> |
| 172 | <td class="top"><a href="index.html" rel="contents">↑ Table of Contents ↑</a></td> |
| 173 | <td class="next"><a href="s3.5.html" rel="next">§3.5 Callout to field >></a></td> |
| 174 | </tr> |
| 175 | </table> |
| 176 | <div class="breadcrumb"><a class="nav" href="s3.html" rel="section">§3 Callout Binding</a></div> |
| 177 | </div> |
| 178 | <div id="footer"> |
Stephan Herrmann | 109893e | 2010-05-18 22:02:53 +0000 | [diff] [blame] | 179 | <hr /><a class="w3c img" href="http://jigsaw.w3.org/css-validator/check/referer" |
| 180 | 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" |
| 181 | width="88" /></a><address>© Stephan Herrmann, Christine Hundt, Marco Mosconi</address> |
Stephan Herrmann | 8f0fa31 | 2010-06-08 18:24:55 +0000 | [diff] [blame^] | 182 | OT/J version 1.3 — last modified: 2010-06-08 |
Stephan Herrmann | 0166441 | 2010-04-01 20:28:43 +0000 | [diff] [blame] | 183 | </div> |
| 184 | </body> |
| 185 | </html> |