blob: 177be5948833cdcce48d50e8f5dd5643828627bc [file] [log] [blame]
<!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.1</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">&lt;&lt;&nbsp;&sect;2.5&nbsp;Abstract Roles</a></td>
<td class="top"><a href="index.html" rel="contents">&uarr;&nbsp;Table of Contents&nbsp;&uarr;</a></td>
<td class="next"><a href="s2.7.html" rel="next">&sect;2.7&nbsp;Advanced structures&nbsp;&gt;&gt;</a></td>
</tr>
</table>
<div class="breadcrumb"><a class="nav" href="s2.html" rel="section">&sect;2&nbsp;Role Binding</a></div>
<div class="sect depth2" id="s2.6">
<h2 class="sect">&sect;2.6&nbsp;Explicit base references<a class="img" href="s2.6.html"
title="PermaLink to &sect;2.6&nbsp;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="&sect;3&nbsp;Callout Binding" class="sect">callout bindings (&sect;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)&nbsp;<span class="title">Externalized roles of a base team</span><a class="img" href="s2.6.a.html"
title="PermaLink to (a)&nbsp;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="&sect;1.2.2&nbsp;Externalized roles" class="sect">&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&lt;@base&gt;</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&lt;@<strong>R1</strong>.base&gt;</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>&lt;@base.<span class="error">field</span>&gt;</code>
or <code>&lt;@<span class="error">field</span>.base&gt;</code>.
</p>
</div>
<div class="subsect depth3" id="s2.6.b">
<h4 class="subsect">(b)&nbsp;<span class="title">Explicit base object creation</span><a class="img" href="s2.6.b.html"
title="PermaLink to (b)&nbsp;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="&sect;2.4.2&nbsp;Role creation via a regular constructor"
class="sect">&sect;2.4.2</a>).
</p>
</div>
<div class="subsect depth3" id="s2.6.c">
<h4 class="subsect">(c)&nbsp;<span class="title">Base call in callin method</span><a class="img" href="s2.6.c.html"
title="PermaLink to (c)&nbsp;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="&sect;4.2.(d)&nbsp;Callin methods" class="sect">callin method (&sect;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="&sect;4.3&nbsp;Base calls" class="sect">&sect;4.3</a>).
</p>
</div>
<div class="subsect depth3" id="s2.6.d">
<h4 class="subsect">(d)&nbsp;<span class="title">Base guard predicates</span><a class="img" href="s2.6.d.html"
title="PermaLink to (d)&nbsp;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="&sect;5.4&nbsp;Guard predicates" class="sect">Guard predicates (&sect;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="&sect;5.4.2.(a)&nbsp;Base object reference"
class="sect">&sect;5.4.2.(a)</a>).
</p>
</div>
<div class="subsect depth3" id="s2.6.e">
<h4 class="subsect">(e)&nbsp;<span class="title">Parameter mappings</span><a class="img" href="s2.6.e.html"
title="PermaLink to (e)&nbsp;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="&sect;4.4&nbsp;Callin parameter mapping"
class="sect">&sect;4.4</a>) or
result in a callout binding (<a href="s3.2.c.html" title="&sect;3.2.(c)&nbsp;Result mapping" class="sect">&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)&nbsp;<span class="title">Inhibition of modification</span><a class="img" href="s2.6.f.html"
title="PermaLink to (f)&nbsp;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)&nbsp;<span class="title">Decapsulation via base reference</span><a class="img" href="s2.6.g.html"
title="PermaLink to (g)&nbsp;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="&sect;2.6.(d)&nbsp;Base guard predicates"
class="sect">&sect;2.6.(d)</a> and <a href="#s2.6.e" title="&sect;2.6.(e)&nbsp;Parameter mappings" class="sect">&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="&sect;3.4.(a)&nbsp;Callout to inaccessible base method"
class="sect">&sect;3.4.(a)</a> and <a href="s3.5.e.html" title="&sect;3.5.(e)&nbsp;Access control" class="sect">&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">&lt;&lt;&nbsp;&sect;2.5&nbsp;Abstract Roles</a></td>
<td class="top"><a href="index.html" rel="contents">&uarr;&nbsp;Table of Contents&nbsp;&uarr;</a></td>
<td class="next"><a href="s2.7.html" rel="next">&sect;2.7&nbsp;Advanced structures&nbsp;&gt;&gt;</a></td>
</tr>
</table>
<div class="breadcrumb"><a class="nav" href="s2.html" rel="section">&sect;2&nbsp;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>&copy; Stephan Herrmann, Christine Hundt, Marco Mosconi</address>
OT/J version 1.3.1 &mdash; last modified: 2013-05-28
</div>
</body>
</html>