<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
  <title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
<br>
<br>
On 17.05.2008 02:03, itsme213 wrote:
<blockquote cite="mid:g0l7cv$f9f$1@ger.gmane.org" type="cite">
  <pre wrap="">"Trygve Reenskaug" <a class="moz-txt-link-rfc2396E" href="mailto:trygver@ifi.uio.no">&lt;trygver@ifi.uio.no&gt;</a> wrote in message

  </pre>
  <blockquote type="cite">
    <pre wrap="">This means that the same object can play several roles at
the same time by simply being bound to several keys. Conversely, the
same role can simultaneously  be played by different objects since there
can be several contexts on the stack at the same time.
    </pre>
  </blockquote>
  <pre wrap=""><!---->
Sounds good.

But can one object play the role Programmer on project 1, and Programmer on 
project 2, at the same time (i.e. the lifetimes of those 2 roles in that 
object overlap) using the same Programmer trait?

Cheers
- Sophie
  </pre>
</blockquote>
The short answer is yes, because the two executions of the same trait
can have different bindings from roles to objects. I'm sure there is a
simple way to explain why this is true, but I have ended up with much
more detail than is actually needed.<br>
<br>
My BabyIDE hides this detail so that the programmer can focus on
the static code and never think about the stack. Programming shall be
simpler, not harder, when using roles as well as the traditional
classes. But here are the details because I cannot make myself delete
them once I have written them:<br>
<br>
It may be misleading to think of traits in isolation here. A role
always occurs in the context of a structure of objects that interact in
order to achieve some common purpose such as a use case. Each
participating object plays a particular role in the interaction. The
role represents the responsibility of the object in the context of the
interaction. The role also names the object so that we can refer to it
in our code, postponing the name-&gt;object binding until the
interaction is actually being executed. Finally, it includes the
methods that describe how the object shall behave when playing its role
in the interaction. <br>
<br>
A role may be played by any object that behaves properly. Therefore, we
do not need
to consider the actual class when writing the code for the role. We
merely reference the object by its role name.&nbsp; <br>
<br>
I have doctored the parser so that a role name in the code is inlined
into a context dictionary lookup. In the following example, the role <tt>Shape1
</tt>is implemented by a trait also called <tt>Shape1</tt>. The trait
defines one or more methods that describe the behavior of any object
that is playing the role. Here's one such method:<br>
&nbsp;&nbsp;&nbsp;<font face="Courier New, Courier, monospace"> </font><tt>Shape1&gt;&gt;play2<br>
&nbsp;&nbsp; &nbsp;&nbsp; &nbsp; &lt;Roles: #(Arrow23)&gt;<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; self displayLarge: '2'.<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Arrow23 play23.</tt><br>
<br>
If&nbsp; I decompile this, I see the context dictionary lookup explicitly:<br>
<br>
&nbsp;&nbsp;&nbsp; <tt>Shape1&gt;&gt;play2<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;Roles: #(#Arrow23)&gt;<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; self displayLarge: '2'.<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; (Baby4Collaboration playerForRole: #Arrow23) play23.<br>
<br>
</tt><tt>playerForRole</tt>: is a class method in <tt>Baby4Collaboration</tt>.
It searches down the stack to find the first context that binds <tt>#Arrow23</tt>
to an object. That object must be instance of a class that uses the
trait <tt>Shape1</tt>.<tt><br>
</tt><br>
A context is put on the stack at the start of the execution of an
interaction, so it&nbsp; only exists for the duration of this execution. I
assume that <tt>project 1</tt> and <tt>project 2</tt> in your example
above are two different executions that may overlap. <br>
<br>
If we are thinking in terms of single-threaded execution, <tt>project 1</tt>
will be put on the stack and the <tt>project 1</tt> bindings will be
the current bindings. If we then enter <tt>project 2</tt>, the <tt>project
2</tt> bindings will be current until the completion of <tt>project 2</tt>.
The <tt>project 2</tt> context will be popped off the stack, and the <tt>project
1</tt> bindings will be current until <tt>project 1</tt> is also
completed. So both bindings can exist at the same time, but only one
can be active in a single-threaded execution.<br>
<br>
If we are thinking in terms of multi-threaded execution, the executions
will have different stacks. So, the project 1 and project 2 contexts
will be on different stacks and the role/trait methods will will bind
role names to different objects since they are executed in different
contexts. And both contexts are active simultaneously.<br>
<br>
Cheers<br>
--Trygve<br>
<br>
<div class="moz-signature">-- <br>
<meta http-equiv="Content-Type" content="text/html; ">
<meta name="ProgId" content="Word.Document">
<meta name="Generator" content="Microsoft Word 10">
<meta name="Originator" content="Microsoft Word 10">
<link rel="File-List" href="TrygveSignature-filer/filelist.xml">
<title>-- </title>
<!--[if gte mso 9]><xml>
 <w:WordDocument>
  <w:SpellingState>Clean</w:SpellingState>
  <w:GrammarState>Clean</w:GrammarState>
  <w:HyphenationZone>21</w:HyphenationZone>
  <w:PunctuationKerning/>
  <w:DrawingGridHorizontalSpacing>6 pt</w:DrawingGridHorizontalSpacing>
  <w:DrawingGridVerticalSpacing>6 pt</w:DrawingGridVerticalSpacing>
  <w:DisplayHorizontalDrawingGridEvery>0</w:DisplayHorizontalDrawingGridEvery>
  <w:DisplayVerticalDrawingGridEvery>3</w:DisplayVerticalDrawingGridEvery>
  <w:UseMarginsForDrawingGridOrigin/>
  <w:DoNotShadeFormData/>
  <w:Compatibility>
   <w:FootnoteLayoutLikeWW8/>
   <w:ShapeLayoutLikeWW8/>
   <w:AlignTablesRowByRow/>
   <w:ForgetLastTabAlignment/>
   <w:LayoutRawTableWidth/>
   <w:LayoutTableRowsApart/>
   <w:UseWord97LineBreakingRules/>
  </w:Compatibility>
  <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel>
 </w:WordDocument>
</xml><![endif]-->
<style>
<!--
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
        {mso-style-parent:"";
        margin:0cm;
        margin-bottom:.0001pt;
        mso-pagination:widow-orphan;
        font-size:12.0pt;
        font-family:"Times New Roman";
        mso-fareast-font-family:"Times New Roman";}
span.SpellE
        {mso-style-name:"";
        mso-spl-e:yes;}
span.GramE
        {mso-style-name:"";
        mso-gram-e:yes;}
 /* Page Definitions */
 @page
        {mso-page-border-surround-header:no;
        mso-page-border-surround-footer:no;}
@page Section1
        {size:612.0pt 792.0pt;
        margin:70.85pt 70.85pt 70.85pt 70.85pt;
        mso-header-margin:35.4pt;
        mso-footer-margin:35.4pt;
        mso-paper-source:0;}
div.Section1
        {page:Section1;}
-->
</style><!--[if gte mso 10]>
<style>
 /* Style Definitions */
 table.MsoNormalTable
        {mso-style-name:"Vanlig tabell";
        mso-tstyle-rowband-size:0;
        mso-tstyle-colband-size:0;
        mso-style-noshow:yes;
        mso-style-parent:"";
        mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
        mso-para-margin:0cm;
        mso-para-margin-bottom:.0001pt;
        mso-pagination:widow-orphan;
        font-size:10.0pt;
        font-family:"Times New Roman";}
</style>
<![endif]--><!--[if gte mso 9]><xml>
 <o:shapedefaults v:ext="edit" spidmax="2050"/>
</xml><![endif]--><!--[if gte mso 9]><xml>
 <o:shapelayout v:ext="edit">
  <o:idmap v:ext="edit" data="1"/>
 </o:shapelayout></xml><![endif]-->
<div class="Section1">
<p class="MsoNormal" style=""><span class="SpellE"><span
 style="font-size: 10pt; font-family: Arial;" lang="EN-GB">Trygve</span></span><span
 style="font-size: 10pt; font-family: Arial;" lang="EN-GB">
Reenskaug<span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>mailto: <span class="SpellE"><a class="moz-txt-link-abbreviated" href="mailto:trygver@ifi.uio.no">trygver@ifi.uio.no</a></span></span><span
 style="font-size: 10pt; font-family: Arial;"><o:p></o:p></span></p>
<p class="MsoNormal" style=""><span class="SpellE"><span class="GramE"><span
 style="font-size: 10pt; font-family: Arial;" lang="EN-GB">Morgedalsvn</span></span></span><span
 class="GramE"><span style="font-size: 10pt; font-family: Arial;"
 lang="EN-GB">.</span></span><span
 style="font-size: 10pt; font-family: Arial;" lang="EN-GB"> 5A <span
 style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><a class="moz-txt-link-freetext" href="http://heim.ifi.uio.no/~trygver">http://heim.ifi.uio.no/~trygver</a><o:p></o:p></span></p>
<p class="MsoNormal" style=""><span
 style="font-size: 10pt; font-family: Arial;">N-0378
Oslo<span style="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>Tel: (+47) 22 49 57 27<o:p></o:p></span></p>
<p class="MsoNormal" style=""><span class="SpellE"><span
 style="font-size: 10pt; font-family: Arial;">Norway</span></span><span
 style="font-size: 10pt; font-family: Arial;"><o:p></o:p></span></p>
</div>
</div>
</body>
</html>