| <!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="s5.4.2.html" rel="prev"><< §5.4.2 Base guards</a></td> |
| <td class="top"><a href="index.html" rel="contents">↑ Table of Contents ↑</a></td> |
| <td class="next"></td> |
| </tr> |
| </table> |
| <div class="breadcrumb"><a class="nav" href="s5.html" rel="section">§5 Team Activation</a> > <a class="nav" href="s5.4.html" rel="section">§5.4 Guard predicates</a></div> |
| <div class="sect depth3" id="s5.4.3"> |
| <h3 class="sect">§5.4.3 Multiple guards<a class="img" href="s5.4.3.html" |
| title="PermaLink to §5.4.3 Multiple guards"><img style="vertical-align:text-top;margin-left:5px;" src="../images/permalink.png" |
| alt="" /></a></h3> |
| <p>Due to the different ranges of applicability different guards may affect the same method binding. |
| In that case all applicable guards are conjoined using a logical <code>and</code>.<br /> |
| Any guard is interpreted as the conjunction of these predicates (if present): |
| |
| </p> |
| <ul> |
| <li>The direct predicate expression of the guard.</li> |
| <li>The next outer guard along the chain |
| <em>method binding -> method -> role level -> team level</em></li> |
| <li>The guard at the same level that is inherited from the <em>implicit</em> super role. |
| </li> |
| <li>The guard at the same level that is inherited from the <em>explicit</em> super role. |
| </li> |
| </ul> |
| <h5 class="listing">Example code (Guard Predicates):</h5> |
| <div class="listing example frame"> |
| <table class="listing"> |
| <tr class="line odd"> |
| <td class="ln">1</td> |
| <td><pre><b>public</b> <b>team</b> <b>class</b> ATM {</pre></td> |
| </tr> |
| <tr class="line even"> |
| <td class="ln">2</td> |
| <td><pre> <b>private</b> Bank myBank;</pre></td> |
| </tr> |
| <tr class="line odd"> |
| <td class="ln">3</td> |
| <td><pre> <b>public</b> <b>class</b> ForeignAccount <b>playedBy</b> Account</pre></td> |
| </tr> |
| <tr class="line even"> |
| <td class="ln">4</td> |
| <td><pre> <em><b>base</b> when</em> (!ATM.this.myBank.equals(<em>base</em>.getBank()))</pre></td> |
| </tr> |
| <tr class="line odd"> |
| <td class="ln">5</td> |
| <td><pre> {</pre></td> |
| </tr> |
| <tr class="line even"> |
| <td class="ln">6</td> |
| <td><pre> <b>callin</b> <b>void</b> debitWithFee(<b>int</b> amount) {</pre></td> |
| </tr> |
| <tr class="line odd"> |
| <td class="ln">7</td> |
| <td><pre> base.debitWithFee(fee+amount);</pre></td> |
| </tr> |
| <tr class="line even"> |
| <td class="ln">8</td> |
| <td><pre> }</pre></td> |
| </tr> |
| <tr class="line odd"> |
| <td class="ln">9</td> |
| <td><pre> <b>void</b> debitWithFee(<b>int</b> i) <b><-</b> <b>replace</b> <b>void</b> debit(<b>int</b> amount)</pre></td> |
| </tr> |
| <tr class="line even"> |
| <td class="ln">10</td> |
| <td><pre> <em><b>base</b> when</em> (amount < 1000);</pre></td> |
| </tr> |
| <tr class="line odd"> |
| <td class="ln">11</td> |
| <td><pre> }</pre></td> |
| </tr> |
| <tr class="line even"> |
| <td class="ln">12</td> |
| <td><pre>}</pre></td> |
| </tr> |
| </table> |
| </div> |
| <div class="codecomment"> |
| <h5>Effects:</h5> |
| The team in this example causes that an additional fee has to be payed while debiting |
| less than 1000 Euros from a "foreign" account. |
| |
| <ul> |
| <li>The base guard in line 4 ensures that <code>Account</code> objects only get |
| <code>ForeignAccount</code> roles, if they belong to a different bank than the |
| surrounding <code>ATM</code> team.<br /> |
| It accesses the bank of the base via the <code>base</code> identifier. |
| |
| </li> |
| <li>The method binding guard in line 10 restricts the callin to |
| <code>debitWithFee</code> to calls where the base method argument |
| <code>amount</code> is lower than 1000. |
| |
| </li> |
| <li>A call to <code>Account.debit</code> causes a replace callin to |
| <code>debitWithFee</code><em> only</em> if <em>both</em> predicates evaluate to true. |
| |
| </li> |
| </ul> |
| </div> |
| </div> |
| <table class="nav"> |
| <tr> |
| <td class="back"><a href="s5.4.2.html" rel="prev"><< §5.4.2 Base guards</a></td> |
| <td class="top"><a href="index.html" rel="contents">↑ Table of Contents ↑</a></td> |
| <td class="next"></td> |
| </tr> |
| </table> |
| <div class="breadcrumb"><a class="nav" href="s5.html" rel="section">§5 Team Activation</a> > <a class="nav" href="s5.4.html" rel="section">§5.4 Guard predicates</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-10-05 |
| </div> |
| </body> |
| </html> |