| <!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.3.2.html" rel="prev"><< §2.3.2 Declared lifting</a></td> |
| <td class="top"><a href="index.html" rel="contents">↑ Table of Contents ↑</a></td> |
| <td class="next"><a href="s2.3.4.html" rel="next">§2.3.4 Binding ambiguities >></a></td> |
| </tr> |
| </table> |
| <div class="breadcrumb"><a class="nav" href="s2.html" rel="section">§2 Role Binding</a> > <a class="nav" href="s2.3.html" rel="section">§2.3 Lifting</a></div> |
| <div class="sect depth3" id="s2.3.3"> |
| <h3 class="sect">§2.3.3 Smart lifting<a class="img" href="s2.3.3.html" |
| title="PermaLink to §2.3.3 Smart lifting"><img style="vertical-align:text-top;margin-left:5px;" src="../images/permalink.png" |
| alt="" /></a></h3> |
| <p>In situations where role and base classes are part of some inheritance |
| hierarchies (<code>extends</code>), choosing the appropriate role class during |
| lifting involves the following rules: |
| |
| </p> |
| <div class="subsect depth4" id="s2.3.3.a"> |
| <h4 class="subsect">(a) <span class="title">Static adjustment</span><a class="img" href="s2.3.3.a.html" |
| title="PermaLink to (a) Static adjustment"><img style="vertical-align:text-top;margin-left:5px;" src="../images/permalink.png" |
| alt="" /></a></h4> |
| <p>If a base class <code>B</code> shall be lifted to a role class |
| <code>R</code> that is not bound to (<code>playedBy</code>) |
| <code>B</code>, but if a subclass of <code>R</code> |
| — say <code>R2</code> — |
| is bound to <code>B</code>, lifting is statically setup to use |
| <code>R2</code>, the most general subclass of <code>R</code> that |
| is bound to <code>B</code> or one of its super-types. |
| |
| </p> |
| <div class="note"> |
| <h5>Restriction:</h5> |
| This step is not applicable for parameter mappings of <code>replace</code> |
| callin bindings (<a href="s4.5.d.html" title="§4.5.(d) Typing rules" class="sect">§4.5.(d)</a>). |
| |
| </div> |
| </div> |
| <div class="subsect depth4" id="s2.3.3.b"> |
| <h4 class="subsect">(b) <span class="title">Dynamic selection of a role class</span><a class="img" href="s2.3.3.b.html" |
| title="PermaLink to (b) Dynamic selection of a role class"><img style="vertical-align:text-top;margin-left:5px;" src="../images/permalink.png" |
| alt="" /></a></h4> |
| <p>At runtime also the dynamic type of a base object is considered: |
| Lifting always tries to use a role class that is bound to the |
| exact class of the base object. Lifting considers all role–base |
| pairs bound by <code>playedBy</code> such that the role class is a |
| sub-class of the required (statically declared) role type |
| and the base class is a super-class of the |
| dynamic type of the base object. |
| <br /> |
| From those possible pairs the most specific base class is chosen. |
| If multiple role classes are bound to this base class the most |
| specific of these classes is chosen. |
| |
| </p> |
| </div> |
| <div class="subsect depth4" id="s2.3.3.c"> |
| <h4 class="subsect">(c) <span class="title">Team as closed world</span><a class="img" href="s2.3.3.c.html" |
| title="PermaLink to (c) Team as closed world"><img style="vertical-align:text-top;margin-left:5px;" src="../images/permalink.png" |
| alt="" /></a></h4> |
| <p>In the above analysis gathering all role-base pairs is performed at |
| compile-time. From this follows, that a team class can only be |
| compiled when all its contained role classes are known and a role class |
| can never be compiled without its team. |
| <br /> |
| The analysis includes all roles and their bindings that are inherited |
| from the super-team. |
| |
| </p> |
| </div> |
| <div class="subsect depth4" id="s2.3.3.d"> |
| <h4 class="subsect">(d) <span class="title">Selection regardless of abstractness</span><a class="img" href="s2.3.3.d.html" |
| title="PermaLink to (d) Selection regardless of abstractness"><img style="vertical-align:text-top;margin-left:5px;" src="../images/permalink.png" |
| alt="" /></a></h4> |
| <p>Smart lifting is not affected by abstractness of role classes. |
| For the effect of abstract role classes see <a href="s2.5.html" title="§2.5 Abstract Roles" class="sect">§2.5</a>. |
| |
| </p> |
| </div> |
| <h5>Complex Example:</h5> |
| <p><img src="../images/smart_lifting_small.png" alt="smart lifting example" /></p> |
| <table border="2" width="80%"> |
| <colgroup span="1"> |
| <col align="left" span="1" /> |
| <col align="left" span="1" /> |
| </colgroup> |
| <tr> |
| <th rowspan="1" colspan="1">role class</th> |
| <th rowspan="1" colspan="1">base class</th> |
| </tr> |
| <tr> |
| <td rowspan="1" colspan="1">class R1</td> |
| <td rowspan="1" colspan="1"> </td> |
| </tr> |
| <tr> |
| <td rowspan="1" colspan="1">class R2 extends R1 playedBy B2</td> |
| <td rowspan="1" colspan="1">class B2</td> |
| </tr> |
| <tr> |
| <td rowspan="1" colspan="1">class R3 extends R2 <em>/* inherited: playedBy B2 */ </em></td> |
| <td rowspan="1" colspan="1">class B3 extends B2</td> |
| </tr> |
| <tr> |
| <td rowspan="1" colspan="1">class R4 extends R3 playedBy B4</td> |
| <td rowspan="1" colspan="1">class B4 extends B3</td> |
| </tr> |
| <tr> |
| <td rowspan="1" colspan="1">class R5 extends R4 <em>/* inherited: playedBy B4 */</em></td> |
| <td rowspan="1" colspan="1"> </td> |
| </tr> |
| <tr> |
| <td rowspan="1" colspan="1"> </td> |
| <td rowspan="1" colspan="1">class B6 extends B4</td> |
| </tr> |
| <tr> |
| <td rowspan="1" colspan="1">class R7 extends R5 playedBy B7</td> |
| <td rowspan="1" colspan="1">class B7 extends B6</td> |
| </tr> |
| </table> |
| <div class="codecomment"> |
| <ul> |
| <li>If declarations require lifting <code>B3</code> to <code>R1</code> |
| this is statically refined to use <code>R2</code> instead, because this |
| is the most general class declaring a binding to a super–class |
| of <code>B3</code>. |
| |
| </li> |
| <li>If the dynamic base type in the same situation is <code>B6</code>, |
| three steps select the appropriate role: |
| |
| <ol> |
| <li>By searching all <code>playedBy</code> clauses (including those |
| that are inherited) the following role–base pairs are |
| candidates:<br /><code>(R2,B2), (R3,B2), (R4,B4)</code> and <code>(R5,B4)</code>. |
| </li> |
| <li>From these pairs the two containing the most specific base class |
| <code>B4</code> are chosen. |
| </li> |
| <li>This makes <code>R4</code> and <code>R5</code> role candidates, |
| from which the most specific <code>R5</code> is finally chosen. |
| </li> |
| </ol> |
| </li> |
| </ul> |
| </div> |
| <p>If the inheritance hierarchies of the involved base and role classes are given (like in the figure above) |
| the smart lifting algorithm can be rephrased to the following "graphical" rule:<br /></p> |
| <div class="note"> |
| Starting with the dynamic base type (<code>B6</code> in the example) move upwards the the inheritance |
| relation until you reach a base class bound to a role class indicated by a «playedBy» |
| arrow pointing to the base class (<code>B4</code>). This role class must be conform to the requested role type. |
| Switch to the role side along this arrow (<code>R4</code>). Now move downwards the role inheritance hierarchy |
| as long as the subrole does not refine the playedBy relationship (indicated by another «playedBy» arrow). |
| The bottom role you reach this way (<code>R5</code>) is the role type selected by smart lifting. |
| |
| </div> |
| </div> |
| <table class="nav"> |
| <tr> |
| <td class="back"><a href="s2.3.2.html" rel="prev"><< §2.3.2 Declared lifting</a></td> |
| <td class="top"><a href="index.html" rel="contents">↑ Table of Contents ↑</a></td> |
| <td class="next"><a href="s2.3.4.html" rel="next">§2.3.4 Binding ambiguities >></a></td> |
| </tr> |
| </table> |
| <div class="breadcrumb"><a class="nav" href="s2.html" rel="section">§2 Role Binding</a> > <a class="nav" href="s2.3.html" rel="section">§2.3 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>© Stephan Herrmann, Christine Hundt, Marco Mosconi</address> |
| OT/J version 1.3 — last modified: 2011-05-12 |
| </div> |
| </body> |
| </html> |