blob: f9f2daceec4d4849123e4a8f4c18a14b06891dd5 [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="s3.3.html" rel="prev">&lt;&lt;&nbsp;&sect;3.3&nbsp;Lifting and lowering</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="s3.5.html" rel="next">&sect;3.5&nbsp;Callout to field&nbsp;&gt;&gt;</a></td>
17 </tr>
18 </table>
19 <div class="breadcrumb"><a class="nav" href="s3.html" rel="section">&sect;3&nbsp;Callout Binding</a></div>
20 <div class="sect depth2" id="s3.4">
Stephan Herrmann109893e2010-05-18 22:02:53 +000021 <h2 class="sect">&sect;3.4&nbsp;Overriding access restrictions<a class="img" href="s3.4.html"
22 title="PermaLink to &sect;3.4&nbsp;Overriding access restrictions"><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 <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="&sect;2.1.2.(c)&nbsp;Base class decapsulation"
34 class="sect">&sect;2.1.2.(c)</a>)
35 </li>
36 <li>base constructor call (see <a href="s2.4.2.b.html" title="&sect;2.4.2.(b)&nbsp;Bound roles" class="sect">&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="&sect;3.5.(e)&nbsp;Access control" class="sect">&sect;3.5.(e)</a>)
40 </li>
41 <li>base call within a callin method (see <a href="s4.6.html" title="&sect;4.6&nbsp;Overriding access restrictions"
42 class="sect">&sect;4.6</a>)
43 </li>
44 </ul>
45 <div class="subsect depth3" id="s3.4.a">
Stephan Herrmann109893e2010-05-18 22:02:53 +000046 <h4 class="subsect">(a)&nbsp;<span class="title">Callout to inaccessible base method</span><a class="img" href="s3.4.a.html"
47 title="PermaLink to (a)&nbsp;Callout to inaccessible base method"><img style="vertical-align:text-top;margin-left:5px;" src="../images/permalink.png"
48 alt="" /></a></h4>
Stephan Herrmann01664412010-04-01 20:28:43 +000049 <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 Herrmann109893e2010-05-18 22:02:53 +000059 <h4 class="subsect">(b)&nbsp;<span class="title">Sealing against decapsulation</span><a class="img" href="s3.4.b.html"
60 title="PermaLink to (b)&nbsp;Sealing against decapsulation"><img style="vertical-align:text-top;margin-left:5px;" src="../images/permalink.png"
61 alt="" /></a></h4>
Stephan Herrmann01664412010-04-01 20:28:43 +000062 <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 Herrmann109893e2010-05-18 22:02:53 +000069 <h4 class="subsect">(c)&nbsp;<span class="title">Warning levels</span><a class="img" href="s3.4.c.html" title="PermaLink to (c)&nbsp;Warning levels"><img style="vertical-align:text-top;margin-left:5px;" src="../images/permalink.png"
70 alt="" /></a></h4>
Stephan Herrmann01664412010-04-01 20:28:43 +000071 <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="&sect;2.1.2.(c)&nbsp;Base class decapsulation"
75 class="sect">&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 Herrmann109893e2010-05-18 22:02:53 +000096 <h4 class="subsect">(d)&nbsp;<span class="title">Private methods from super classes</span><a class="img" href="s3.4.d.html"
97 title="PermaLink to (d)&nbsp;Private methods from super classes"><img style="vertical-align:text-top;margin-left:5px;" src="../images/permalink.png"
98 alt="" /></a></h4>
Stephan Herrmann01664412010-04-01 20:28:43 +000099 <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="&sect;3.1.(d)&nbsp;Inheritance of role method declarations"
104 class="sect">&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>-&gt;</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>-&gt;</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">&lt;&lt;&nbsp;&sect;3.3&nbsp;Lifting and lowering</a></td>
172 <td class="top"><a href="index.html" rel="contents">&uarr;&nbsp;Table of Contents&nbsp;&uarr;</a></td>
173 <td class="next"><a href="s3.5.html" rel="next">&sect;3.5&nbsp;Callout to field&nbsp;&gt;&gt;</a></td>
174 </tr>
175 </table>
176 <div class="breadcrumb"><a class="nav" href="s3.html" rel="section">&sect;3&nbsp;Callout Binding</a></div>
177 </div>
178 <div id="footer">
Stephan Herrmann109893e2010-05-18 22:02:53 +0000179 <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>&copy; Stephan Herrmann, Christine Hundt, Marco Mosconi</address>
Stephan Herrmann8f0fa312010-06-08 18:24:55 +0000182 OT/J version 1.3 &mdash; last modified: 2010-06-08
Stephan Herrmann01664412010-04-01 20:28:43 +0000183 </div>
184 </body>
185</html>