blob: 54fa76f708463e99708e2d47a14daa996fc38f3b [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.1.2.a.html" rel="prev">&lt;&lt;&nbsp;&sect;2.1.2.(a)&nbsp;No role of the same team</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.1.2.c.html" rel="next">&sect;2.1.2.(c)&nbsp;Base class decapsulation&nbsp;&gt;&gt;</a></td>
</tr>
</table>
<div class="breadcrumb"><a class="nav" href="s2.html" rel="section">&sect;2&nbsp;Role Binding</a>&nbsp;&gt;&nbsp;<a class="nav" href="s2.1.html" rel="section">&sect;2.1&nbsp;playedBy relation</a>&nbsp;&gt;&nbsp;<a class="nav" href="s2.1.2.html" rel="section">&sect;2.1.2&nbsp;Legal base classes</a></div>
<div class="subsect depth4" id="s2.1.2.b">
<h4 class="subsect">&sect;2.1.2.(b)&nbsp;<span class="title">Cycles</span><a class="img" href="s2.1.2.b.html" title="PermaLink to (b)&nbsp;Cycles"><img style="vertical-align:text-top;margin-left:5px;" src="../images/permalink.png"
alt="" /></a></h4>
<p>The base class mentioned after <code>playedBy</code> should normally not be
an enclosing type (at any depth) of the role class being defined.
<br />
This rule discourages the creation of cycles where the base instance of
a given role <code>R</code> contains roles of the same type <code>R</code>.
<br />
More generally this concerns any sequence of classes <code>C<sub>1</sub>, C<sub>2</sub>, .. C<sub>n</sub></code>
were each <code>C<sub>i+1</sub></code> is either a member or the base class of
<code>C<sub>i</sub></code> and <code>C<sub>n</sub> = C<sub>1</sub></code>.
<br />
Such structures may be difficult to understand and have certain restrictions regarding
callout (<a href="s3.1.a.html" title="&sect;3.1.(a)&nbsp;Prerequisite: Class binding"
class="sect">&sect;3.1.(a)</a>) and base constructor calls (<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>).
It is furthermore recommended to equip all roles that are played by an enclosing class with a guard predicate (<a href="s5.4.html" title="&sect;5.4&nbsp;Guard predicates" class="sect">&sect;5.4</a>) like this:
</p>
<div class="listing plain"><pre><em>base</em><em> when</em> (MyTeam.this == <em>base</em>)</pre></div>
<p>
This will avoid that the role adapts other instances of the enclosing class which are not the enclosing instance.
</p>
<p>
It is prohibited to bind a role class to its own inner class.
</p>
</div>
<table class="nav">
<tr>
<td class="back"><a href="s2.1.2.a.html" rel="prev">&lt;&lt;&nbsp;&sect;2.1.2.(a)&nbsp;No role of the same team</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.1.2.c.html" rel="next">&sect;2.1.2.(c)&nbsp;Base class decapsulation&nbsp;&gt;&gt;</a></td>
</tr>
</table>
<div class="breadcrumb"><a class="nav" href="s2.html" rel="section">&sect;2&nbsp;Role Binding</a>&nbsp;&gt;&nbsp;<a class="nav" href="s2.1.html" rel="section">&sect;2.1&nbsp;playedBy relation</a>&nbsp;&gt;&nbsp;<a class="nav" href="s2.1.2.html" rel="section">&sect;2.1.2&nbsp;Legal base classes</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>