| <!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><a href="s2.5.html" rel="prev"><< §2.5 Abstract Roles</a></td> |
| <td class="top"><a href="index.html" rel="contents">↑ Table of Contents ↑</a></td> |
| <td class="next"><a href="s2.7.html" rel="next">§2.7 Advanced structures >></a></td> |
| </tr> |
| </table> |
| <div class="breadcrumb"><a class="nav" href="s2.html" rel="section">§2 Role Binding</a></div> |
| <div class="sect depth2" id="s2.6"> |
| <h2 class="sect">§2.6 Explicit base references<a class="img" href="s2.6.html" |
| title="PermaLink to §2.6 Explicit base references"><img style="vertical-align:text-top;margin-left:5px;" src="../images/permalink.png" |
| alt="" /></a></h2> |
| <p>The role-base link is not meant to be accessed explicitly from programs, |
| but it is fully under the control of compiler and runtime environment. |
| Accessing features of a role's base object is done by |
| <a href="s3.html" title="§3 Callout Binding" class="sect">callout bindings (§3)</a>. |
| Yet, a keyword <code>base</code> exists, which can be used in the following |
| contexts: |
| |
| </p> |
| <div class="subsect depth3" id="s2.6.a"> |
| <h4 class="subsect">(a) <span class="title">Externalized roles of a base team</span><a class="img" href="s2.6.a.html" |
| title="PermaLink to (a) Externalized roles of a base team"><img style="vertical-align:text-top;margin-left:5px;" src="../images/permalink.png" |
| alt="" /></a></h4> |
| <p>If the base class of a role <code>T1.R1</code> is again a team |
| <code>T2</code>, roles of that team <code>T2</code> can be |
| externalized (see <a href="s1.2.2.html" title="§1.2.2 Externalized roles" class="sect">§1.2.2</a>) |
| using <code>base</code> as their type anchor. Given that |
| <code>R2</code> is a role of <code>T2</code>, one could write: |
| |
| </p> |
| <div class="listing example frame"> |
| <table class="listing"> |
| <tr class="line odd"> |
| <td class="ln">1</td> |
| <td><pre><b>public</b> <b>team</b> <b>class</b> T1 {</pre></td> |
| </tr> |
| <tr class="line even"> |
| <td class="ln">2</td> |
| <td><pre> <b>protected</b> <b>class</b> R1 <em><b>playedBy</b> T2</em> {</pre></td> |
| </tr> |
| <tr class="line odd"> |
| <td class="ln">3</td> |
| <td><pre> <b>protected</b> <em>R2<@base></em> aRoleOfMyBase;</pre></td> |
| </tr> |
| <tr class="line even"> |
| <td class="ln">4</td> |
| <td><pre> }</pre></td> |
| </tr> |
| <tr class="line odd"> |
| <td class="ln">5</td> |
| <td><pre>}</pre></td> |
| </tr> |
| </table> |
| </div> |
| <p>This syntax is only legal within the body of the role <code>T1.R1</code> which is bound |
| to the team <code>T2</code> containing role <code>R2</code>. |
| A static type prefix can be used to disambiguate a base anchor, so the explicit variant |
| of the above type would be <code>R2<@<strong>R1</strong>.base></code>. |
| <br /> |
| It is not legal to use a type anchor containing <code>base</code> as an element in a path |
| of references like <code><@base.<span class="error">field</span>></code> |
| or <code><@<span class="error">field</span>.base></code>. |
| |
| </p> |
| </div> |
| <div class="subsect depth3" id="s2.6.b"> |
| <h4 class="subsect">(b) <span class="title">Explicit base object creation</span><a class="img" href="s2.6.b.html" |
| title="PermaLink to (b) Explicit base object creation"><img style="vertical-align:text-top;margin-left:5px;" src="../images/permalink.png" |
| alt="" /></a></h4> |
| <p>Within a role constructor (which is not the lifting constructor) |
| the syntax <code>base(<em>arguments</em>)</code> causes an instance |
| of the bound base class to be created and linked (see <a href="s2.4.2.html" |
| title="§2.4.2 Role creation via a regular constructor" |
| class="sect">§2.4.2</a>). |
| |
| </p> |
| </div> |
| <div class="subsect depth3" id="s2.6.c"> |
| <h4 class="subsect">(c) <span class="title">Base call in callin method</span><a class="img" href="s2.6.c.html" |
| title="PermaLink to (c) Base call in callin method"><img style="vertical-align:text-top;margin-left:5px;" src="../images/permalink.png" |
| alt="" /></a></h4> |
| <p>Within a <a href="s4.2.d.html" title="§4.2.(d) Callin methods" class="sect">callin method (§4.2.(d))</a> |
| an expression <code>base.m(<em>args</em>)</code> is used to invoke the |
| originally called method (see <a href="s4.3.html" title="§4.3 Base calls" class="sect">§4.3</a>). |
| |
| </p> |
| </div> |
| <div class="subsect depth3" id="s2.6.d"> |
| <h4 class="subsect">(d) <span class="title">Base guard predicates</span><a class="img" href="s2.6.d.html" |
| title="PermaLink to (d) Base guard predicates"><img style="vertical-align:text-top;margin-left:5px;" src="../images/permalink.png" |
| alt="" /></a></h4> |
| <p><a href="s5.4.html" title="§5.4 Guard predicates" class="sect">Guard predicates (§5.4)</a> can |
| be specified to act on the base side using the <code><strong>base when</strong></code> keywords. |
| Within such a base guard predicate <code>base</code> is interpreted as a special identifier |
| holding a reference to the base object that is about to be lifted |
| for the sake of a callin method interception (see <a href="s5.4.2.a.html" title="§5.4.2.(a) Base object reference" |
| class="sect">§5.4.2.(a)</a>). |
| |
| </p> |
| </div> |
| <div class="subsect depth3" id="s2.6.e"> |
| <h4 class="subsect">(e) <span class="title">Parameter mappings</span><a class="img" href="s2.6.e.html" |
| title="PermaLink to (e) Parameter mappings"><img style="vertical-align:text-top;margin-left:5px;" src="../images/permalink.png" |
| alt="" /></a></h4> |
| <p>An expression at the right-hand side of a parameter mapping |
| (parameter in a callin binding (<a href="s4.4.html" title="§4.4 Callin parameter mapping" |
| class="sect">§4.4</a>) or |
| result in a callout binding (<a href="s3.2.c.html" title="§3.2.(c) Result mapping" class="sect">§3.2.(c)</a>) ) may use the keyword <code>base</code> |
| to refer to the bound base instance. Such usage requires the role method bound in this method binding to be non-static. |
| |
| </p> |
| </div> |
| <div class="subsect depth3" id="s2.6.f"> |
| <h4 class="subsect">(f) <span class="title">Inhibition of modification</span><a class="img" href="s2.6.f.html" |
| title="PermaLink to (f) Inhibition of modification"><img style="vertical-align:text-top;margin-left:5px;" src="../images/permalink.png" |
| alt="" /></a></h4> |
| <p>In all cases, the <code>base</code> reference is immutable, |
| i.e., <code>base</code> can never appear as the left-hand-side of an assignment. |
| |
| </p> |
| </div> |
| <div class="subsect depth3" id="s2.6.g"> |
| <h4 class="subsect">(g) <span class="title">Decapsulation via base reference</span><a class="img" href="s2.6.g.html" |
| title="PermaLink to (g) Decapsulation via base reference"><img style="vertical-align:text-top;margin-left:5px;" src="../images/permalink.png" |
| alt="" /></a></h4> |
| <p>In cases <a href="#s2.6.d" title="§2.6.(d) Base guard predicates" |
| class="sect">§2.6.(d)</a> and <a href="#s2.6.e" title="§2.6.(e) Parameter mappings" class="sect">§2.6.(e)</a> above, members of the base |
| object may be accessed that would not be visible under Java's visibility rules. |
| Such references are treated as decapsulation in accordance with <a href="s3.4.a.html" |
| title="§3.4.(a) Callout to inaccessible base method" |
| class="sect">§3.4.(a)</a> and <a href="s3.5.e.html" title="§3.5.(e) Access control" class="sect">§3.5.(e)</a>.<br /> |
| Note that accessing a base field via <code>base</code> only gives reading access to this field. |
| |
| </p> |
| </div> |
| <div class="newpage"></div> |
| </div> |
| <table class="nav"> |
| <tr> |
| <td class="back"><a href="s2.5.html" rel="prev"><< §2.5 Abstract Roles</a></td> |
| <td class="top"><a href="index.html" rel="contents">↑ Table of Contents ↑</a></td> |
| <td class="next"><a href="s2.7.html" rel="next">§2.7 Advanced structures >></a></td> |
| </tr> |
| </table> |
| <div class="breadcrumb"><a class="nav" href="s2.html" rel="section">§2 Role 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> |