blob: efe94c9cbf8bb436af395a6d9dad1965ba460bd0 [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.3.d.html" rel="prev">&lt;&lt;&nbsp;&sect;2.3.(d)&nbsp;Lifting of arrays</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.3.2.html" rel="next">&sect;2.3.2&nbsp;Declared lifting&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.3.html" rel="section">&sect;2.3&nbsp;Lifting</a></div>
<div class="sect depth3" id="s2.3.1">
<h3 class="sect">&sect;2.3.1&nbsp;Implicit role creation<a class="img" href="s2.3.1.html"
title="PermaLink to &sect;2.3.1&nbsp;Implicit role creation"><img style="vertical-align:text-top;margin-left:5px;" src="../images/permalink.png"
alt="" /></a></h3>
<p>Lifting tries to reuse existing role objects so that role state persists across
lifting and lowering. If no suitable role instance is found during lifting,
a new role is created.
</p>
<div class="subsect depth4" id="s2.3.1.a">
<h4 class="subsect">(a)&nbsp;<span class="title">Reuse of existing role objects</span><a class="img" href="s2.3.1.a.html"
title="PermaLink to (a)&nbsp;Reuse of existing role objects"><img style="vertical-align:text-top;margin-left:5px;" src="../images/permalink.png"
alt="" /></a></h4>
<p>A role object is considered suitable for reuse during lifting, if
these three items are identical:
</p>
<ol>
<li>the given base object</li>
<li>the given team object</li>
<li>the statically required role type</li>
</ol>
<p>For the relation between the statically required role type and
the actual type of the role object see <a href="s2.3.3.html" title="&sect;2.3.3&nbsp;Smart lifting" class="sect">"smart lifting" (&sect;2.3.3)</a>.
</p>
</div>
<div class="subsect depth4" id="s2.3.1.b">
<h4 class="subsect">(b)&nbsp;<span class="title">Default lifting constructor</span><a class="img" href="s2.3.1.b.html"
title="PermaLink to (b)&nbsp;Default lifting constructor"><img style="vertical-align:text-top;margin-left:5px;" src="../images/permalink.png"
alt="" /></a></h4>
<p>Lifting uses a default constructor which takes exactly one argument of the type
of the declared base class (after <code>playedBy</code>).
By default the compiler generates such a constructor for each bound role.
On the other hand, default constructors that take no arguments
(as in <a href="http://java.sun.com/docs/books/jls/second_edition/html/classes.doc.html#16823"
class="ext">JLS &sect;8.8.7</a>) are never generated for bound roles.
<br />
The super-constructor to be invoked by a default lifting constructor
depends on whether the role's super class is a bound role or not.
</p>
<ul>
<li>If the super-class is a bound role, the default lifting constructor will invoke the default lifting constructor of the super-class.</li>
<li>If the super-class is not a bound role, the default lifting constructor will invoke the normal argumentless default constructor
of the super-class.
</li>
</ul>
</div>
<div class="subsect depth4" id="s2.3.1.c">
<h4 class="subsect">(c)&nbsp;<span class="title">Custom lifting constructor</span><a class="img" href="s2.3.1.c.html"
title="PermaLink to (c)&nbsp;Custom lifting constructor"><img style="vertical-align:text-top;margin-left:5px;" src="../images/permalink.png"
alt="" /></a></h4>
<p>If a role class declares a custom constructor with the same signature
as the default lifting constructor, this constructor is used during lifting.
This custom constructor may pre-assume that the role has been setup
properly regarding its base-link and registered in the team's internal map of roles.
<br />
If a bound role has an unbound super-class without an argumentless
constructor, providing a custom lifting constructor is obligatory,
because no legal default lifting constructor can be generated.
</p>
</div>
<div class="subsect depth4" id="s2.3.1.d">
<h4 class="subsect">(d)&nbsp;<span class="title">Fine-tuning role instantiation</span><a class="img" href="s2.3.1.d.html"
title="PermaLink to (d)&nbsp;Fine-tuning role instantiation"><img style="vertical-align:text-top;margin-left:5px;" src="../images/permalink.png"
alt="" /></a></h4>
<p>If the lifting operation as defined above degrades the program performance, the lifting semantics can be modified per role
class
by adding the annotation <code>@org.objectteams.Instantiation</code> which requires an argument of type
<code>org.objectteams.InstantiationPolicy</code> in order to select between the following behaviors:
</p>
<dl>
<dt>ONDEMAND</dt>
<dd>This is the default behavior as defined above.</dd>
<dt>ALWAYS</dt>
<dd>This strategy avoids maintaining the internal role cache, but instead a fresh role instance is created for each lifting request.
This may increase the number of role instances but cuts the costs of accessing the cache, which could otherwise become
expensive if a cache grows large. As a result of this strategy role state can no longer be shared
over time, thus it is discouraged to define fields in a role with this strategy. Also, comparing roles could lead
to
unexpected results. Therefor, roles with this strategy should implement custom <code>equals</code> and <code>hashCode</code>
methods, which should simply delegate to the base instance (using callout <a href="s3.html" title="&sect;3&nbsp;Callout Binding" class="sect">&sect;3</a>).
</dd>
<dt>NEVER</dt>
<dd>Roles with this instantiation policy are never instantiated by lifting.
Such roles cannot define non-static fields.
Otherwise this optimization is fully transparent, specifically callout bindings will refer to the correct base instance.<br />
As of version 2.0 the OT/J compiler does not implement this strategy.
</dd>
<dt>SINGLETON</dt>
<dd>Roles declaring this strategy will be instantiated at most once per team. Subsequent lifting requests in the same team
will always answer the same role instance. Such roles may receive triggers from callin bindings, but cannot define
callout bindings.<br />
As of version 2.0 the OT/J compiler does not implement this strategy.
</dd>
</dl>
</div>
</div>
<table class="nav">
<tr>
<td class="back"><a href="s2.3.d.html" rel="prev">&lt;&lt;&nbsp;&sect;2.3.(d)&nbsp;Lifting of arrays</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.3.2.html" rel="next">&sect;2.3.2&nbsp;Declared lifting&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.3.html" rel="section">&sect;2.3&nbsp;Lifting</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>