blob: 332f9c0dfc86c9657888279f50b405ab96ddb555 [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</title>
</head>
<body class="otdt">
<div id="content">
<table class="nav">
<tr>
<td class="back"><a id="top"></a><a href="s2.6.html" rel="prev">&lt;&lt;&nbsp;&sect;2.6&nbsp;Explicit base references</a></td>
<td class="top"><a href="index.html" rel="contents">&uarr;&nbsp;Table of Contents&nbsp;&uarr;</a></td>
<td class="next"></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.7">
<h2 class="sect">&sect;2.7&nbsp;Advanced structures<a class="img" href="s2.7.html"
title="PermaLink to &sect;2.7&nbsp;Advanced structures"><img style="vertical-align:text-top;margin-left:5px;" src="../images/permalink.png"
alt="" /></a></h2>
<p>This section discusses how role containment and the playedBy relationship can be combined.
It does not define new rules, but illustrates rules defined above. The central idea is that any class
can have more than one of the three flavors <em>team, role, </em>and<em> base</em>.
</p>
<div class="subsect depth3" id="s2.7.a">
<h4 class="subsect">(a)&nbsp;<span class="title">Nesting</span><a class="img" href="s2.7.a.html" title="PermaLink to (a)&nbsp;Nesting"><img style="vertical-align:text-top;margin-left:5px;" src="../images/permalink.png"
alt="" /></a></h4>
<p>If a role (contained in a team) is also a team (marked with the <code>team</code> modifier)
it is a <strong>nested team</strong>. The depth of nesting is not restricted.
</p>
</div>
<div class="subsect depth3" id="s2.7.b">
<h4 class="subsect">(b)&nbsp;<span class="title">Stacking</span><a class="img" href="s2.7.b.html" title="PermaLink to (b)&nbsp;Stacking"><img style="vertical-align:text-top;margin-left:5px;" src="../images/permalink.png"
alt="" /></a></h4>
<p>If the base class to which a role is bound using <code>playedBy</code> is a team,
the role is said to be <strong>stacked</strong> on the base team.
</p>
</div>
<div class="subsect depth3" id="s2.7.c">
<h4 class="subsect">(c)&nbsp;<span class="title">Layering</span><a class="img" href="s2.7.c.html" title="PermaLink to (c)&nbsp;Layering"><img style="vertical-align:text-top;margin-left:5px;" src="../images/permalink.png"
alt="" /></a></h4>
<p>If roles of a team <code>Secondary</code> are played by roles of another team <code>Primary</code>
(i.e., base classes are roles), the team <code>Secondary</code> defines a <strong>layer</strong> over the team <code>Primary</code>.
Such layering requires a final reference <code>anchor</code> from <code>Secondary</code> to an instance of <code>Primary</code>.
All playedBy declarations within <code>Secondary</code> specify their base classes anchored to that final link <code>anchor</code>.
</p><img src="../images/Layering.png" alt="Team layering example" /><p>Due to the anchored base types, layered teams implicitly support the following guarantee:
all base objects of roles of <code>Secondary</code> are contained within the team instance specified by the link <code>anchor</code>.
If roles of <code>Secondary</code> contain any callin bindings to non-static base methods, these will be triggered only
when a base method is invoked on a base instance contained in the team specified by <code>anchor</code>.
<br />
In accordance with <a href="s2.6.a.html"
title="&sect;2.6.(a)&nbsp;Externalized roles of a base team"
class="sect">&sect;2.6.(a)</a> the anchor in such anchored playedBy declarations
could also be the pseudo identifier <code>base</code>, provided that <code>Secondary</code> is a nested team,
which has a playedBy binding to <code>Primary</code> as its base class.
This situation is part of the second example <a href="#s2.7.d" title="&sect;2.7.(d)&nbsp;Implicit playedBy specialization"
class="sect">below (&sect;2.7.(d))</a> (see <code>T1 playedBy TB1</code>).
</p>
</div>
<div class="newpage"></div>
<div class="subsect depth3" id="s2.7.d">
<h4 class="subsect">(d)&nbsp;<span class="title">Implicit playedBy specialization</span><a class="img" href="s2.7.d.html"
title="PermaLink to (d)&nbsp;Implicit playedBy specialization"><img style="vertical-align:text-top;margin-left:5px;" src="../images/permalink.png"
alt="" /></a></h4>
<p>According to <a href="s2.1.d.html" title="&sect;2.1.(d)&nbsp;No-variance" class="sect">&sect;2.1.(d)</a> an implicit sub-role may <em>implicitly</em> specialize an existing <code>playedBy</code> relation.
This requires the base class to be specified relative to some implicit (<code>OuterTeam.this</code>) or explicit (<code>OuterTeam.base</code>) team anchor.
Specializing that team anchor automatically specializes the playedBy declaration, too.
This rule never requires any action from a programmer but only explains the interpretation of a playedBy declaration in
complex situations.
</p>
<h5>Two advanced examples demonstrating the above are:</h5>
<table border="0">
<colgroup span="1">
<col align="left" span="1" />
<col align="left" span="1" />
</colgroup>
<tr>
<td rowspan="1" colspan="1">
<ul>
<li>If a role <code>TOuter1.T.R</code> of a <strong>nested team </strong><code>TOuter1.T</code> is played by
another role of the outer enclosing team <code>TOuter1.B</code>, subclassing the outer team <code>TOuter1</code> to <code>TOuter2</code>
will produce a new role <code>TOuter2.T.R</code> which is automatically played by <code>TOuter2.B</code>,
an implicit sub class of the original base class <code>TOuter1.B</code>.
</li>
</ul>
</td>
<td rowspan="1" colspan="1"><img src="../images/implicitly_overriding_playedby.png"
alt="Implicitly overriding playedBy" /></td>
</tr>
<tr>
<td rowspan="1" colspan="1">
<ul>
<li>Consider the case where a <strong>nested </strong><code>T1</code> as a role of <code>TOuter</code> is <strong>stacked</strong>
on a base team <code>TB1</code>. Also, <code>T1</code> is a <strong>layered team</strong> over <code>TB1</code>
because its role <code>R</code> adapts role <code>TB1.B</code>.
<br />
In this situation the playedBy relation of role <code>TOuter.T1.R</code> is given by a base-anchored type <code>B&lt;@T1.base&gt;</code>.
If furthermore <code>TOuter.T1</code> is subclassed to <code>TOuter.T2</code> which covariantly refines the inherited
playedBy declaration to <code>TB2</code>, then <code>TOuter.T2.R</code> will automatically refine the inherited playedBy relation
to <code>TB2.B</code> to follow the new interpretation of the <code>base</code> anchor.
</li>
</ul>
</td>
<td rowspan="1" colspan="1"><img src="../images/implicitly_overriding_playedby_base.png"
alt="Implicitly overriding playedBy base" /></td>
</tr>
</table>
</div>
</div>
<table class="nav">
<tr>
<td class="back"><a href="s2.6.html" rel="prev">&lt;&lt;&nbsp;&sect;2.6&nbsp;Explicit base references</a></td>
<td class="top"><a href="index.html" rel="contents">&uarr;&nbsp;Table of Contents&nbsp;&uarr;</a></td>
<td class="next"></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 &mdash; last modified: 2011-05-15
</div>
</body>
</html>