| <!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.2.2.html" rel="next">§1.2.2 Externalized roles >></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.2.html" rel="section">§1.2 Role classes and objects</a></div> |
| <div class="sect depth3" id="s1.2.1"> |
| <h3 class="sect">§1.2.1 Modifiers for roles<a class="img" href="s1.2.1.html" |
| title="PermaLink to §1.2.1 Modifiers for roles"><img style="vertical-align:text-top;margin-left:5px;" src="../images/permalink.png" |
| alt="" /></a></h3> |
| <p>Member classes of a team cannot be <code>static</code>. |
| Also the use of access modifiers for roles is restricted and modifiers have different (stronger) semantics than for |
| regular classes (see below). With respect to accessibility a team acts mainly like a package regarding its roles. |
| |
| </p> |
| <div class="subsect depth4" id="s1.2.1.a"> |
| <h4 class="subsect">(a) <span class="title">Role class protection</span><a class="img" href="s1.2.1.a.html" |
| title="PermaLink to (a) Role class protection"><img style="vertical-align:text-top;margin-left:5px;" src="../images/permalink.png" |
| alt="" /></a></h4> |
| <p>A role class must have exactly one of the access modifiers <code>public</code> |
| or <code>protected</code>.<br /> |
| This rule does not affect the class modifiers <code>abstract</code>, <code>final</code> and <code>strictfp</code>. |
| |
| </p> |
| </div> |
| <div class="subsect depth4" id="s1.2.1.b"> |
| <h4 class="subsect">(b) <span class="title">protected role classes</span><a class="img" href="s1.2.1.b.html" |
| title="PermaLink to (b) protected role classes"><img style="vertical-align:text-top;margin-left:5px;" src="../images/permalink.png" |
| alt="" /></a></h4> |
| <p>A <code>protected</code> role can only be accessed from within the enclosing |
| team or any of its sub-teams. The actual border of encapsulation is the |
| enclosing team <em>instance</em>. The rules for protected roles are given |
| in <a href="s1.2.3.html" title="§1.2.3 Protected roles" class="sect">§1.2.3</a> below. |
| |
| </p> |
| </div> |
| <div class="subsect depth4" id="s1.2.1.c"> |
| <h4 class="subsect">(c) <span class="title">public role classes</span><a class="img" href="s1.2.1.c.html" |
| title="PermaLink to (c) public role classes"><img style="vertical-align:text-top;margin-left:5px;" src="../images/permalink.png" |
| alt="" /></a></h4> |
| <p>Only <code>public</code> roles can ever be accessed outside their enclosing team. |
| Accessing a role outside the enclosing team instance is governed by the rules |
| of <strong>externalized roles</strong>, to be defined next (<a href="s1.2.2.html" title="§1.2.2 Externalized roles" class="sect">§1.2.2</a>). |
| |
| </p> |
| </div> |
| <div class="subsect depth4" id="s1.2.1.d"> |
| <h4 class="subsect">(d) <span class="title">abstract role classes</span><a class="img" href="s1.2.1.d.html" |
| title="PermaLink to (d) abstract role classes"><img style="vertical-align:text-top;margin-left:5px;" src="../images/permalink.png" |
| alt="" /></a></h4> |
| <p>A role class has to be marked <strong>abstract</strong> if any of its methods |
| is not effective.<br /> |
| The <em>methods of a role class</em> comprise direct methods and |
| methods acquired by inheritance. |
| In addition to regular inheritance a role class may acquire methods |
| also via implicit inheritance (<a href="s1.3.1.html" |
| title="§1.3.1 Acquisition and implicit inheritance of role classes" |
| class="sect">§1.3.1</a>).<br /> |
| A method may become <em>effective</em> by either: |
| |
| </p> |
| <ul> |
| <li>implementation (i.e., a regular method body), or</li> |
| <li>a callout binding (see <a href="s3.html" title="§3 Callout Binding" class="sect">§3</a>). |
| </li> |
| </ul> |
| <p><a href="s2.5.html" title="§2.5 Abstract Roles" class="sect">§2.5</a> discusses under which |
| circumstances abstract roles force the enclosing team to be abstract, too. |
| |
| |
| </p> |
| </div> |
| <div class="subsect depth4" id="s1.2.1.e"> |
| <h4 class="subsect">(e) <span class="title">Role features</span><a class="img" href="s1.2.1.e.html" title="PermaLink to (e) Role features"><img style="vertical-align:text-top;margin-left:5px;" src="../images/permalink.png" |
| alt="" /></a></h4> |
| <p>Access modifiers for members of roles have some special interpretation: |
| |
| </p> |
| <ol> |
| <li>A private member is also visible in any implicit sub role |
| (see implicit inheritance <a href="s1.3.1.c.html" |
| title="§1.3.1.(c) Overriding and implicit inheritance" |
| class="sect">§1.3.1.(c)</a>).<br /> |
| In contrast to inner classes in Java, private members of a role are not |
| visible to the enclosing team. |
| </li> |
| <li>The default visibility of role members restricts access to the |
| current class and its sub-classes (explicit and implicit). |
| </li> |
| <li><code>protected</code> role members can only be accessed from the enclosing |
| team or via <a href="s4.html" title="§4 Callin Binding" class="sect">callin (§4)</a>. |
| </li> |
| <li><code>public</code> role members grant unrestricted access. |
| </li> |
| </ol> |
| <p>Additionally, a role always has access to all the features that its enclosing team has access to.</p> |
| <p>Only <code>public</code> members can ever be accessed via an <a href="s1.2.2.html" title="§1.2.2 Externalized roles" class="sect">externalized role (§1.2.2)</a>. |
| |
| </p> |
| </div> |
| <div class="subsect depth4" id="s1.2.1.f"> |
| <h4 class="subsect">(f) <span class="title">Static role methods</span><a class="img" href="s1.2.1.f.html" |
| title="PermaLink to (f) Static role methods"><img style="vertical-align:text-top;margin-left:5px;" src="../images/permalink.png" |
| alt="" /></a></h4> |
| <p>In contrast to inner classes in pure Java, a role class may indeed define static methods. A static role method requires no |
| role |
| instance <em>but</em> it still requires a team instance in scope. Static role methods can be called: |
| |
| </p> |
| <ul> |
| <li>from the enclosing team,</li> |
| <li>via callin (see <a href="s4.7.html" title="§4.7 Callin binding with static methods" |
| class="sect">§4.7</a>). |
| </li> |
| </ul> |
| <p>Within a static role method the syntax <code>MyTeam.this</code> is available for accessing the enclosing team instance. |
| |
| </p> |
| </div> |
| <div class="subsect depth4" id="s1.2.1.g"> |
| <h4 class="subsect">(g) <span class="title">No static initializers</span><a class="img" href="s1.2.1.g.html" |
| title="PermaLink to (g) No static initializers"><img style="vertical-align:text-top;margin-left:5px;" src="../images/permalink.png" |
| alt="" /></a></h4> |
| <p>A static field of a role class must not have a non-constant initialization expression. |
| Static initialization blocks are already prohibited for inner classes by Java (see <a href="http://java.sun.com/docs/books/jls/second_edition/html/classes.doc.html#262890" |
| class="ext">JLS §8.1.2</a>). |
| |
| </p> |
| <div class="note"> |
| <h5>Note:</h5> |
| Static initialization generally provides a means for performing initialization code prior to instantiation, i.e., at |
| class-loading time. |
| Before any role can be created already two levels of initialization are performed: (1) The (outer most) enclosing team |
| class performs static initializations when it is loaded. (2) Any enclosing team executes |
| its constructor when it is instantiated. It should be possible to allocate any early initialization to either of these |
| two phases instead of using static role initializers. |
| |
| </div> |
| </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.2.2.html" rel="next">§1.2.2 Externalized roles >></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.2.html" rel="section">§1.2 Role classes and objects</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-15 |
| </div> |
| </body> |
| </html> |