| <!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></td> |
| <td class="top"><a href="index.html" rel="contents">↑ Table of Contents ↑</a></td> |
| <td class="next"><a href="s1.3.2.html" rel="next">§1.3.2 Regular role inheritance >></a></td> |
| </tr> |
| </table> |
| <div class="breadcrumb"><a class="nav" href="s1.html" rel="section">§1 Teams and Roles</a> > <a class="nav" href="s1.3.html" rel="section">§1.3 Acquisition and implicit inheritance of role classes</a></div> |
| <div class="sect depth3" id="s1.3.1"> |
| <h3 class="sect">§1.3.1 Acquisition and implicit inheritance of role classes<a class="img" href="s1.3.1.html" |
| title="PermaLink to §1.3.1 Acquisition and implicit inheritance of role classes"><img style="vertical-align:text-top;margin-left:5px;" src="../images/permalink.png" |
| alt="" /></a></h3> |
| <p>A team acquires all roles from its super-team. This relation is |
| similar to inheritance of inner classes, but with a few decisive |
| differences as defined next. Two implementation options are mentioned <a href="s1.html#aux1.1" class="int">below</a>, |
| which can be used to realize the special semantics of role |
| acquisition (virtual classes and copy inheritance). |
| |
| </p> |
| <h5 class="listing">Implicit role inheritance</h5> |
| <div class="listing example frame" id="l1.3.1-1"> |
| <table class="listing"> |
| <tr class="line odd"> |
| <td class="ln">1</td> |
| <td><pre><b>public</b> <b>team</b> <b>class</b> S {</pre></td> |
| </tr> |
| <tr class="line even"> |
| <td class="ln">2</td> |
| <td><pre> <b>protected</b> <b>class</b> R0 {...}</pre></td> |
| </tr> |
| <tr class="line odd"> |
| <td class="ln">3</td> |
| <td><pre> <b>protected</b> <b>class</b> R1 <em><b>extends</b> R0</em> {</pre></td> |
| </tr> |
| <tr class="line even"> |
| <td class="ln">4</td> |
| <td><pre> <b>boolean</b> ok;</pre></td> |
| </tr> |
| <tr class="line odd"> |
| <td class="ln">5</td> |
| <td><pre> R2 m() {...}</pre></td> |
| </tr> |
| <tr class="line even"> |
| <td class="ln">6</td> |
| <td><pre> <b>void</b> n(<em>R2</em> r) {...}</pre></td> |
| </tr> |
| <tr class="line odd"> |
| <td class="ln">7</td> |
| <td><pre> }</pre></td> |
| </tr> |
| <tr class="line even"> |
| <td class="ln">8</td> |
| <td><pre> <b>protected</b> <b>class</b> R2 {...}</pre></td> |
| </tr> |
| <tr class="line odd"> |
| <td class="ln">9</td> |
| <td><pre>}</pre></td> |
| </tr> |
| </table> |
| </div> |
| <div class="listing example frame" id="l1.3.1-2"> |
| <table class="listing"> |
| <tr class="line odd"> |
| <td class="ln">10</td> |
| <td><pre><b>public</b> <b>team</b> <b>class</b> T <em><b>extends</b> S</em> {</pre></td> |
| </tr> |
| <tr class="line even"> |
| <td class="ln">11</td> |
| <td><pre> @Override <b>protected</b> <em><b>class</b> R1</em> {</pre></td> |
| </tr> |
| <tr class="line odd"> |
| <td class="ln">12</td> |
| <td><pre> <strong>R2</strong> m() {</pre></td> |
| </tr> |
| <tr class="line even"> |
| <td class="ln">13</td> |
| <td><pre> if(<em>ok</em>) { <b>return</b> <em>tsuper</em>.m(); }</pre></td> |
| </tr> |
| <tr class="line odd"> |
| <td class="ln">14</td> |
| <td><pre> <b>else</b> { <b>return</b> null; }</pre></td> |
| </tr> |
| <tr class="line even"> |
| <td class="ln">15</td> |
| <td><pre> }</pre></td> |
| </tr> |
| <tr class="line odd"> |
| <td class="ln">16</td> |
| <td><pre> <b>void</b> doIt() {</pre></td> |
| </tr> |
| <tr class="line even"> |
| <td class="ln">17</td> |
| <td><pre> n(m());</pre></td> |
| </tr> |
| <tr class="line odd"> |
| <td class="ln">18</td> |
| <td><pre> }</pre></td> |
| </tr> |
| <tr class="line even"> |
| <td class="ln">19</td> |
| <td><pre> }</pre></td> |
| </tr> |
| <tr class="line odd"> |
| <td class="ln">20</td> |
| <td><pre>}</pre></td> |
| </tr> |
| </table> |
| </div> |
| <div class="subsect depth4" id="s1.3.1.a"> |
| <h4 class="subsect">(a) <span class="title">Role class acquisition</span><a class="img" href="s1.3.1.a.html" |
| title="PermaLink to (a) Role class acquisition"><img style="vertical-align:text-top;margin-left:5px;" src="../images/permalink.png" |
| alt="" /></a></h4> |
| <p>A team <code>T</code> which extends a super-team <code>S</code> |
| has one role class <code>T.R</code> corresponding to each role <code>S.R</code> |
| of the super-team. |
| The new type <code>T.R</code> <strong>overrides</strong> <code>R</code> for the |
| context of <code>T</code> and its roles. |
| Acquisition of role classes can either be direct (see (b) below), or |
| it may involve overriding and implicit inheritance ((c) below). |
| |
| </p> |
| <div class="codecomment">In the above example (<a href="#l1.3.1-1" class="listing">Listing 1.3.1-1</a>) the team <code>S</code> operates |
| on types <code>S.R0</code>, <code>S.R1</code> and <code>S.R2</code>, |
| while <code>T</code> operates on types <code>T.R0</code>, <code>T.R1</code> |
| and <code>T.R2</code>.<br /><em>(Type references like "<code>S.R0</code>" are actually illegal in source code |
| (<a href="s1.2.3.b.html" title="§1.2.3.(b) Qualified role types" |
| class="sect">§1.2.3.(b)</a>). Here they are used for explanatory purposes only)</em></div> |
| </div> |
| <div class="subsect depth4" id="s1.3.1.b"> |
| <h4 class="subsect">(b) <span class="title">Direct role acquisition</span><a class="img" href="s1.3.1.b.html" |
| title="PermaLink to (b) Direct role acquisition"><img style="vertical-align:text-top;margin-left:5px;" src="../images/permalink.png" |
| alt="" /></a></h4> |
| <p>Within a sub-team <code>T</code> each role <code>S.R</code> of its |
| super-team <code>S</code> is available by the simple name <code>R</code> |
| without further declaration. |
| |
| </p> |
| <div class="codecomment">The role <code>R2</code> in <a href="#l1.3.1-1" class="listing">Listing 1.3.1-1</a> can be used in the sub-team |
| <code>T</code> (line 12), because this role type is defined in the super class of the enclosing team. |
| |
| </div> |
| </div> |
| <div class="subsect depth4" id="s1.3.1.c"> |
| <h4 class="subsect">(c) <span class="title">Overriding and implicit inheritance</span><a class="img" href="s1.3.1.c.html" |
| title="PermaLink to (c) Overriding and implicit inheritance"><img style="vertical-align:text-top;margin-left:5px;" src="../images/permalink.png" |
| alt="" /></a></h4> |
| <p>If a team contains a role class definition by the same name as |
| a role defined in its super-team, |
| the new role class overrides the corresponding role from the super-team |
| and <strong>implicitly inherits</strong> all of its features. |
| Such relation is established only by name correspondence. |
| |
| </p> |
| <p>A role that overrides an inherited role should be marked with an <code>@Override</code> annotation. |
| A compiler should optionally flag a missing <code>@Override</code> annotation with a warning. |
| Conversely, it is an error if a role is marked with an <code>@Override</code> annotation but does not actually |
| override an inherited role. |
| |
| </p> |
| <p>It is an error to override a role class with an interface or vice versa. A final role cannot be overridden.<br /> |
| Unlike regular inheritance, <strong>constructors</strong> are also inherited |
| along implicit inheritance, and can be overridden just like normal methods. |
| |
| </p> |
| <div class="codecomment"> |
| In <a href="#l1.3.1-1" class="listing">Listing 1.3.1-1</a><code> R1</code> in <code>T</code> implicitly inherits all features of |
| <code>R1</code> in <code>S</code>. This is, because its enclosing team |
| <code>T</code> extends the team <code>S</code> (line 10) and the role |
| definition uses the same name <code>R1</code> (line 11). |
| Hence the attribute <code><strong>ok</strong></code> is available in the method |
| <code>m()</code> in <code>T.R1</code> (line 13). <code>T.R1</code> also overrides <code>S.R1</code> |
| which is marked by the <code>@Override</code> annotation in line 11. |
| |
| </div> |
| </div> |
| <div class="subsect depth4" id="s1.3.1.d"> |
| <h4 class="subsect">(d) <span class="title">Lack of subtyping</span><a class="img" href="s1.3.1.d.html" |
| title="PermaLink to (d) Lack of subtyping"><img style="vertical-align:text-top;margin-left:5px;" src="../images/permalink.png" |
| alt="" /></a></h4> |
| <p>Direct acquisition of roles from a super-team and implicit inheritance |
| do not establish a <strong>subtype</strong> relation. |
| A role of a given team is never conform (i.e., substitutable) |
| to any role of any <em>other</em> team. |
| <code>S.R</code> and <code>T.R</code> are always incommensurable.<br /><span class="underline">Note,</span> that this rule is a direct consequence of <a href="s1.2.2.e.html" title="§1.2.2.(e) Conformance" class="sect">§1.2.2.(e)</a>. |
| |
| </p> |
| </div> |
| <div class="subsect depth4" id="s1.3.1.e"> |
| <h4 class="subsect">(e) <span class="title">Dynamic binding of types</span><a class="img" href="s1.3.1.e.html" |
| title="PermaLink to (e) Dynamic binding of types"><img style="vertical-align:text-top;margin-left:5px;" src="../images/permalink.png" |
| alt="" /></a></h4> |
| <p>Overriding an acquired role by a new role class has the following |
| implication: If an expression or declaration, which is evaluated on behalf of |
| an instance of team <code>T</code> or one of its contained roles, |
| refers to a role <code>R</code>, <code>R</code> will always |
| resolve to <code>T.R</code> even if <code>R</code> was introduced in |
| a super-team of <code>T</code> and even if the specific line of code |
| was inherited from a super-team or one of its roles. |
| Only the dynamic type of the enclosing team-instance is used to determine |
| the correct role class (see below for an example). |
| |
| </p> |
| <p>A special case of dynamically binding role types relates to so-called class literals |
| (see <a href="http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#251530" |
| class="ext">JLS §15.8.2</a>). |
| Role class literals are covered in <a href="s6.1.c.html" title="§6.1.(c) Class literals for roles" |
| class="sect">§6.1.(c)</a>. |
| |
| </p> |
| <p>The above is strictly needed only for cases involving implicit inheritance. |
| It may, however, help intuition, to also consider the directly acquired |
| role <code>T.R</code> in (b) to override the given role <code>S.R</code>. |
| |
| </p> |
| <div class="codecomment"> |
| In line 17 of <a href="#l1.3.1-1" class="listing">Listing 1.3.1-1</a> the implicitly inherited method <code>n</code> is called |
| with the result of an invocation of <code>m</code>. Although |
| <code>n</code> was defined in <code>S</code> (thus with argument type |
| <code>S.R2, see line 6</code>) in the context of <code>T</code> it |
| expects an argument of <code>T.R2</code>. This is correctly provided by |
| the invocation of <code>m</code> in the context of <code>T</code>. |
| |
| </div> |
| </div> |
| <div class="subsect depth4" id="s1.3.1.f"> |
| <h4 class="subsect">(f) <span class="title">tsuper</span><a class="img" href="s1.3.1.f.html" title="PermaLink to (f) tsuper"><img style="vertical-align:text-top;margin-left:5px;" src="../images/permalink.png" |
| alt="" /></a></h4> |
| <div class="syntaxlink"><a href="sA.html#sA.5.4" title="§A.5.4 TSuperCall" class="syntax">→ Syntax §A.5.4</a></div> |
| <p>Super calls along implicit inheritance use the new keyword |
| <strong>tsuper</strong>. While <code>super</code> is still available |
| along regular inheritance, a call <code>tsuper.m()</code> |
| selects the version of <code>m</code> of the corresponding role |
| acquired from the super-team. |
| |
| </p> |
| <p>See <a href="s2.4.2.html" |
| title="§2.4.2 Role creation via a regular constructor" |
| class="sect">§2.4.2</a> for <code>tsuper</code> |
| in the context of role constructors. |
| |
| </p> |
| <p><code>tsuper</code> can only be used to invoke a corresponding |
| version of the enclosing method or constructor, i.e., an expression |
| <code>tsuper.m()</code> may only occur within the method <code>m</code> |
| with both methods having the same signature |
| (see <a href="s2.3.2.b.html" |
| title="§2.3.2.(b) Super in the context of declared lifting" |
| class="sect">§2.3.2.(b)</a> for an exception, where both methods have slightly different signatures). |
| |
| </p> |
| <div class="codecomment"> |
| In <a href="#l1.3.1-1" class="listing">Listing 1.3.1-1</a> the role <code>R1</code> in team <code>T</code> |
| overrides the implicitly inherited method <code>m()</code> from <code>S</code>. <code><strong>tsuper</strong>.m()</code> calls the overridden method <code>m()</code> |
| from <code>S.R1</code> (line 13). |
| |
| </div> |
| </div> |
| <div class="subsect depth4" id="s1.3.1.g"> |
| <h4 class="subsect">(g) <span class="title">Implicitly inheriting super-types</span><a class="img" href="s1.3.1.g.html" |
| title="PermaLink to (g) Implicitly inheriting super-types"><img style="vertical-align:text-top;margin-left:5px;" src="../images/permalink.png" |
| alt="" /></a></h4> |
| <p>If a role class has an explicit super class (using <code>extends</code>) |
| this relation is inherited along implicit inheritance. |
| |
| </p> |
| <div class="codecomment"> |
| In <a href="#l1.3.1-1" class="listing">Listing 1.3.1-1</a> the role <code>R1</code> in <code>T</code> has <code>T.R0</code> |
| as its implicitly inherited super class, because the corresponding role in the super-team |
| <code><strong>extends R0</strong></code> (line 3). |
| |
| </div> |
| <p>Overriding an implicitly inherited super class is governed by |
| <a href="s1.3.2.b.html" |
| title="§1.3.2.(b) Inheriting and overriding the extends clause" |
| class="sect">§1.3.2.(b)</a>, below.<br /> |
| The list of implemented interfaces is merged along implicit |
| inheritance. |
| |
| </p> |
| </div> |
| <div class="subsect depth4" id="s1.3.1.h"> |
| <h4 class="subsect">(h) <span class="title">Preserving visibility</span><a class="img" href="s1.3.1.h.html" |
| title="PermaLink to (h) Preserving visibility"><img style="vertical-align:text-top;margin-left:5px;" src="../images/permalink.png" |
| alt="" /></a></h4> |
| <p>A role class must provide at least as much access as the implicit super role, |
| or a compile-time error occurs (this is in analogy to <a href="http://java.sun.com/docs/books/jls/second_edition/html/classes.doc.html#227965" |
| class="ext">JLS §8.4.6.3</a>). |
| Access rights of methods overridden by implicit inheritance follow |
| the same rules as for normal overriding. |
| |
| </p> |
| </div> |
| <div class="subsect depth4" id="s1.3.1.i"> |
| <h4 class="subsect">(i) <span class="title">Dynamic binding of constructors</span><a class="img" href="s1.3.1.i.html" |
| title="PermaLink to (i) Dynamic binding of constructors"><img style="vertical-align:text-top;margin-left:5px;" src="../images/permalink.png" |
| alt="" /></a></h4> |
| <p>When creating a role instance using <code>new</code> not only the |
| type to instantiate is bound dynamically (cf. <a href="#s1.3.1.e" title="§1.3.1.(e) Dynamic binding of types" |
| class="sect">§1.3.1.(e)</a>), but also the constructor to |
| invoke is dynamically bound in accordance to the concrete |
| type.<br /> |
| Within role constructors all <code>this(..)</code> and |
| <code>super(..)</code> calls are bound statically with respect to explicit inheritance |
| and dynamically with respect to implicit inheritance. This means the target role name is |
| determined statically, but using that name the suitable role type is determined |
| using dynamic binding. |
| <br /> |
| See also <a href="s2.5.a.html" |
| title="§2.5.(a) Using abstract classes for creation" |
| class="sect">§2.5.(a)</a> on using constructors of abstract role classes. |
| |
| </p> |
| </div> |
| <div class="subsect depth4" id="s1.3.1.j"> |
| <h4 class="subsect">(j) <span class="title">Overriding and compatibility</span><a class="img" href="s1.3.1.j.html" |
| title="PermaLink to (j) Overriding and compatibility"><img style="vertical-align:text-top;margin-left:5px;" src="../images/permalink.png" |
| alt="" /></a></h4> |
| <p>The rules of <a href="http://java.sun.com/docs/books/jls/second_edition/html/classes.doc.html#228745" |
| class="ext">JLS §8.4.6</a> |
| also apply to methods <em>and constructors</em> inherited via implicit inheritance. |
| |
| </p> |
| </div> |
| <div class="subsect depth4" id="s1.3.1.k"> |
| <h4 class="subsect">(k) <span class="title">Covariant return types</span><a class="img" href="s1.3.1.k.html" |
| title="PermaLink to (k) Covariant return types"><img style="vertical-align:text-top;margin-left:5px;" src="../images/permalink.png" |
| alt="" /></a></h4> |
| <p>Given a team <code>T1</code> with two roles <code>R1</code> and <code>R2</code> where <code>R2</code> explicitly inherits from <code>R1</code>, both roles defining |
| a method <code>m</code> returning some type <code>A</code>. |
| Given also a sub-team of <code>T1</code>, <code>T2</code>, where <code>T2.R1</code> overrides <code>m</code> with a covariant return type <code>B</code> |
| (sub-type of <code>A</code>): |
| |
| </p> |
| <div class="listing plain"><pre> <b>public</b> <b>team</b> <b>class</b> T1 { |
| <b>protected</b> <b>abstract</b> <b>class</b> R1 { |
| <b>abstract</b> A m(); |
| } |
| <b>protected</b> <b>class</b> R2 <b>extends</b> R1 { |
| A m() { <b>return</b> <b>new</b> A(); } |
| } |
| } |
| <b>public</b> <b>team</b> <b>class</b> T2 <b>extends</b> T1 { |
| <b>protected</b> <b>class</b> R1 { |
| @Override B m() { <b>return</b> <b>new</b> B(); } <span class="error">// this declaration renders <b>class</b> T2.R2 illegal</span> |
| } |
| }</pre></div> |
| <p> |
| In this situation role <code>T2.R2</code> will be illegal unless also overriding <code>m</code> with a return type that is at least <code>B</code>. |
| Note, that the actual error occurs at the implicitly inherited method <code>T2.R2.m</code> which is not visible in the source code, |
| even <code>T2.R2</code> need not be mentioned explicitly in the source code. |
| A compiler should flag this as an imcompatibility at the team level, because a team must specialize inherited roles |
| in a consistent way. |
| |
| </p> |
| </div> |
| <h5 class="listing">Example code (Teams and Roles):</h5> |
| <div class="listing example frame" id="l1.3.1-3"> |
| <table class="listing"> |
| <tr class="line odd"> |
| <td class="ln">1</td> |
| <td><pre><b>public</b> <b>team</b> <b>class</b> MyTeamA {</pre></td> |
| </tr> |
| <tr class="line even"> |
| <td class="ln">2</td> |
| <td><pre> <b>protected</b> <b>class</b> MyRole {</pre></td> |
| </tr> |
| <tr class="line odd"> |
| <td class="ln">3</td> |
| <td><pre> String name;</pre></td> |
| </tr> |
| <tr class="line even"> |
| <td class="ln">4</td> |
| <td><pre> <b>public</b> MyRole (String n) { name = n; }</pre></td> |
| </tr> |
| <tr class="line odd"> |
| <td class="ln">5</td> |
| <td><pre> <b>public</b> <b>void</b> print() { System.out.println("id="+name); }</pre></td> |
| </tr> |
| <tr class="line even"> |
| <td class="ln">6</td> |
| <td><pre> }</pre></td> |
| </tr> |
| <tr class="line odd"> |
| <td class="ln">7</td> |
| <td><pre> <b>protected</b> MyRole getRole() { <b>return</b> <b>new</b> MyRole("Joe"); }</pre></td> |
| </tr> |
| <tr class="line even"> |
| <td class="ln">8</td> |
| <td><pre>}</pre></td> |
| </tr> |
| </table> |
| </div> |
| <div class="listing example frame" id="l1.3.1-4"> |
| <table class="listing"> |
| <tr class="line odd"> |
| <td class="ln">10</td> |
| <td><pre><b>public</b> <b>team</b> <b>class</b> MySubTeam <b>extends</b> MyTeamA {</pre></td> |
| </tr> |
| <tr class="line even"> |
| <td class="ln">11</td> |
| <td><pre> <b>protected</b> <b>class</b> MyRole {</pre></td> |
| </tr> |
| <tr class="line odd"> |
| <td class="ln">12</td> |
| <td><pre> <b>int</b> age;</pre></td> |
| </tr> |
| <tr class="line even"> |
| <td class="ln">13</td> |
| <td><pre> <b>public</b> <b>void</b> setAge(<b>int</b> a) { age = a; }</pre></td> |
| </tr> |
| <tr class="line odd"> |
| <td class="ln">14</td> |
| <td><pre> <b>public</b> <b>void</b> print() {</pre></td> |
| </tr> |
| <tr class="line even"> |
| <td class="ln">15</td> |
| <td><pre> tsuper.print();</pre></td> |
| </tr> |
| <tr class="line odd"> |
| <td class="ln">16</td> |
| <td><pre> System.out.println("age="+age);</pre></td> |
| </tr> |
| <tr class="line even"> |
| <td class="ln">17</td> |
| <td><pre> }</pre></td> |
| </tr> |
| <tr class="line odd"> |
| <td class="ln">18</td> |
| <td><pre> }</pre></td> |
| </tr> |
| <tr class="line even"> |
| <td class="ln">19</td> |
| <td><pre> <b>public</b> <b>void</b> doit() {</pre></td> |
| </tr> |
| <tr class="line odd"> |
| <td class="ln">20</td> |
| <td><pre> MyRole r = getRole();</pre></td> |
| </tr> |
| <tr class="line even"> |
| <td class="ln">21</td> |
| <td><pre> r.setAge(27);</pre></td> |
| </tr> |
| <tr class="line odd"> |
| <td class="ln">22</td> |
| <td><pre> r.print();</pre></td> |
| </tr> |
| <tr class="line even"> |
| <td class="ln">23</td> |
| <td><pre> }</pre></td> |
| </tr> |
| <tr class="line odd"> |
| <td class="ln">24</td> |
| <td><pre>}</pre></td> |
| </tr> |
| <tr class="line even"> |
| <td class="ln">25</td> |
| <td><pre>...</pre></td> |
| </tr> |
| <tr class="line odd"> |
| <td class="ln">26</td> |
| <td><pre>MySubTeam myTeam = <b>new</b> MySubTeam();</pre></td> |
| </tr> |
| <tr class="line even"> |
| <td class="ln">27</td> |
| <td><pre>myTeam.doit();</pre></td> |
| </tr> |
| </table> |
| </div> |
| <h5 class="listing">Program output</h5> |
| <div class="listing example frame"><pre>id=Joe |
| age=27</pre></div> |
| <div class="codecomment"> |
| <h5>Effects:</h5> |
| <ul> |
| <li>According to <a href="s1.3.html" |
| title="§1.3 Acquisition and implicit inheritance of role classes" |
| class="sect">§1.3</a>, <code>MyTeamA</code> implements |
| <code>ITeam</code> (line 1). |
| </li> |
| <li>An implicit role inheritance is created for |
| <code>MySubTeam.MyRole</code> (<a href="#s1.3.1.c" |
| title="§1.3.1.(c) Overriding and implicit inheritance" |
| class="sect">§1.3.1.(c)</a>; line 11).<br /> |
| If we visualize this special inheritance using a fictitious keyword |
| <code>overrides</code> the compiler would see a declaration: |
| |
| <div class="listing plain"><pre><b>protected</b> <b>class</b> MyRole <em>overrides MyTeamA.MyRole</em> { ... }</pre></div> |
| </li> |
| <li>Invoking <code>getRole()</code> on <code>myTeam</code> (line 27, 20) |
| creates an instance of <code>MySubTeam.MyRole</code> because the |
| acquired role <code>MyTeamA.MyRole</code> is overridden by |
| <code>MySubTeam.MyRole</code> |
| following the rules of implicit inheritance (cf. <a href="#s1.3.1.e" title="§1.3.1.(e) Dynamic binding of types" |
| class="sect">§1.3.1.(e)</a>). |
| |
| </li> |
| <li>Overriding of role methods and access to inherited features works as usual. |
| |
| </li> |
| <li>As an example for <a href="#s1.3.1.f" title="§1.3.1.(f) tsuper" class="sect">§1.3.1.(f)</a> see the call <code>tsuper.print()</code> |
| (line 15), which selects the implementation of <code>MyTeamA.MyRole.print</code>. |
| |
| </li> |
| </ul> |
| </div> |
| </div> |
| <table class="nav"> |
| <tr> |
| <td class="back"></td> |
| <td class="top"><a href="index.html" rel="contents">↑ Table of Contents ↑</a></td> |
| <td class="next"><a href="s1.3.2.html" rel="next">§1.3.2 Regular role inheritance >></a></td> |
| </tr> |
| </table> |
| <div class="breadcrumb"><a class="nav" href="s1.html" rel="section">§1 Teams and Roles</a> > <a class="nav" href="s1.3.html" rel="section">§1.3 Acquisition and implicit inheritance of role 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>© Stephan Herrmann, Christine Hundt, Marco Mosconi</address> |
| OT/J version 1.3 — last modified: 2010-06-08 |
| </div> |
| </body> |
| </html> |