<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Tahoma
}
--></style>
</head>
<body class='hmmessage'>
Great!&nbsp;<div><br></div><div>I didn't see John's reply but it's definitely the best way :)</div><div><br></div><div>Thanks a lot everyone!</div><div>I'll surely come with new problems as I'm new with smalltalk&nbsp;</div><div>Regards,</div><div>Alex<br><br><hr id="stopSpelling">Date: Fri, 29 Oct 2010 20:43:49 +0200<br>From: sebastian_heidbrink@yahoo.de<br>To: seaside@lists.squeakfoundation.org<br>Subject: Re: [Seaside] Dynamic typing in smalltalk<br><br>

  
<meta http-equiv="Content-Type" content="text/html; charset=unicode">
<meta name="Generator" content="Microsoft SafeHTML">
    
  
  
    As far as I can see there's no need for your loop.<br>
    John's solution already provides you with a class in selectedType.<br>
    <br>
    Eventhough it isn't quite the way to do it.<br>
    You forgot something here. Symbol new returns a Symbol:<br>
    <br>
    <div>
      <div style="text-indent:0px ! important">&nbsp;dynamicTyping :=
        ('PaperBibli', selectedType) asSymbol asClass.</div>
      <div style="text-indent:0px ! important">bibEntry := PaperBibli
        perform: dynamicTyping new.<br>
        <br>
        asClass isn't nice because it take some while and there are more
        OO-solutions available.<br>
        Try to get away from casting. Delegation is the answer.<br>
        <br>
        If you might need to keep your original Object, or, how to say
        this right now, whish or need to keep on using the memory space
        you could also use become: or becomeWith:<br>
        Now this is really not the nice way to do it, but it schould
        also work.<br>
        <br>
        yourmessage: aPaperBibli<br>
        ^PaperArticle new become: aPaperBibli<br>
      </div>
    </div>
    <br>
    Just to be mentioned...<br>
    <br>
    I would use John's approch, it's the most common.<br>
    <br>
    Sebastian<br>
    <br>
    Am 29.10.2010 20:23, schrieb Alexandre BP:
    <blockquote cite="mid:SNT138-w1979CBBEBA097C565F6EF09F450@phx.gbl">
      <style>
.ExternalClass .ecxhmmessage P
{padding:0px;}
.ExternalClass body.ecxhmmessage
{font-size:10pt;font-family:Tahoma;}

</style>
      thanks for your time,
      <div>Your second solution seems very nice I'll try it as soon as
        possible.</div>
      <div><br>
      </div>
      <div>The second one however forces me to have a big list of loops
        that look like '(selectedType = 'Book') ifTrue: [var :=
        PaperBibliArticle new]. '&nbsp;</div>
      <div>which is neither clean nor evolutive.</div>
      <div>I wanted to do something like:</div>
      <div><br>
      </div>
      <div>&nbsp;dynamicTyping := ('PaperBibli', selectedType, ' new')
        asSymbol.</div>
      <div>bibEntry := PaperBibli perform: dynamicTyping.</div>
      <div><br>
      </div>
      <div>OR</div>
      <div><br>
      </div>
      <div>
        
        <div style="text-indent:0px ! important">&nbsp;dynamicTyping :=
          ('PaperBibli', selectedType) asSymbol.</div>
        <div style="text-indent:0px ! important">bibEntry :=
          PaperBibli perform: dynamicTyping new.</div>
      </div>
      <div><br>
      </div>
      <div>--&gt; it doesn't work unfortunately ...</div>
      <div><br>
      </div>
      <div>OR:</div>
      <div><br>
      </div>
      <div>As in JAVA:</div>
      <div><br>
      </div>
      <div>PaperBibli bibEntry;</div>
      <div><br>
      </div>
      <div>(when I need it)</div>
      <div>bibEntry = new PaperBibliArticle;</div>
      <div><br>
      </div>
      <div>Anyway I'll try the second solution which is more elegant.</div>
      <div>thank you very much</div>
      <div>alex</div>
      <div><br>
      </div>
      <div><br>
      </div>
      <div>&nbsp;</div>
      <div><br>
        &gt; Date: Fri, 29 Oct 2010 13:56:14 -0300<br>
        &gt; From: <a class="ecxmoz-txt-link-abbreviated" href="mailto:andres@lifia.info.unlp.edu.ar">andres@lifia.info.unlp.edu.ar</a><br>
        &gt; To: <a class="ecxmoz-txt-link-abbreviated" href="mailto:seaside@lists.squeakfoundation.org">seaside@lists.squeakfoundation.org</a><br>
        &gt; Subject: Re: [Seaside] Dynamic typing in smalltalk<br>
        &gt; <br>
        &gt; Hi Alexandre,<br>
        &gt; I guess you could try two approaches:<br>
        &gt; <br>
        &gt; 1. Just list the classes in a select, so that the first
        step is choosing <br>
        &gt; the entry. Once you have this you just create the
        appropriate class.<br>
        &gt; <br>
        &gt; 2. Decouple the type of the object from the object itself
        (check also <br>
        &gt; <a class="ecxmoz-txt-link-freetext" href="http://www.ksc.com/article3.htm" target="_blank">http://www.ksc.com/article3.htm</a>). Thus PaperBibli would
        know an object <br>
        &gt; (lets say PaperType) whose subclasses would be Book,
        Article, etc. When <br>
        &gt; the user selects the type he wants you just set the
        object's type. The <br>
        &gt; type class is the one that holds the type-specific
        information.<br>
        &gt; <br>
        &gt; HTH,<br>
        &gt; Andrés<br>
        &gt; <br>
        &gt; Alexandre BP escribió:<br>
        &gt; &gt; thank you for your replyI have a class named
        "PaperBibli" which keeps a list of bibliographic entries.Those
        entries are of different type: Article, Book,
        Conference,...Every type has its own fields such as:
        author,title,...<br>
        &gt; &gt; --&gt; I created SubClasses of "PaperBibli" for each
        type so that when I instanciate an bibliographic entry I don't
        have lots of variables(fields) which are empty because not
        required in a particular type.The problem is that when I
        instanciate my bibliographic entry I still don't know of which
        type it is because the user tell me so by choosing in a scroll
        list.<br>
        &gt; &gt; I hope that my explanation is clear<br>
        &gt; &gt; <br>
        &gt; &gt; <br>
        &gt; &gt; <br>
        &gt; &gt; Date: Fri, 29 Oct 2010 12:24:22 -0400<br>
        &gt; &gt; Subject: Re: [Seaside] Dynamic typing in smalltalk<br>
        &gt; &gt; From: <a class="ecxmoz-txt-link-abbreviated" href="mailto:sean@monkeysnatchbanana.com">sean@monkeysnatchbanana.com</a><br>
        &gt; &gt; To: <a class="ecxmoz-txt-link-abbreviated" href="mailto:seaside@lists.squeakfoundation.org">seaside@lists.squeakfoundation.org</a><br>
        &gt; &gt; <br>
        &gt; &gt; There are types in smalltalk. Each object has a type.<br>
        &gt; &gt; That aside, what are you trying to accomplish with
        your example below?<br>
        &gt; &gt; <br>
        &gt; &gt; On Fri, Oct 29, 2010 at 12:13 PM, Alexandre BP
        <a class="ecxmoz-txt-link-rfc2396E" href="mailto:abalonpe@ulb.ac.be">&lt;abalonpe@ulb.ac.be&gt;</a> wrote:<br>
        &gt; &gt; <br>
        &gt; &gt; <br>
        &gt; &gt; <br>
        &gt; &gt; <br>
        &gt; &gt; <br>
        &gt; &gt; <br>
        &gt; &gt; <br>
        &gt; &gt; Hello,<br>
        &gt; &gt; I would like to know if it is possible to apply
        dynamic typing in smalltalk. For example, If I want to use
        polymorphism, it would be: <br>
        &gt; &gt; var := Class new. var := (SubClass1) message. var :=
        (SubClass2) message.<br>
        &gt; &gt; <br>
        &gt; &gt; Where message from SubClass1 is different then the one
        from SubClass2.Is there any solution for my problem? I know that
        there is no type in smalltalk but there is definitely a way to
        use polymorphism right?<br>
        &gt; &gt; <br>
        &gt; &gt; Thank you in advance,Regardsalex <br>
        &gt; &gt; <br>
        &gt; &gt; _______________________________________________<br>
        &gt; &gt; <br>
        &gt; &gt; seaside mailing list<br>
        &gt; &gt; <br>
        &gt; &gt; <a class="ecxmoz-txt-link-abbreviated" href="mailto:seaside@lists.squeakfoundation.org">seaside@lists.squeakfoundation.org</a><br>
        &gt; &gt; <br>
        &gt; &gt;
        <a class="ecxmoz-txt-link-freetext" href="http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside" target="_blank">http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside</a><br>
        &gt; &gt; <br>
        &gt; &gt; <br>
        &gt; &gt; <br>
        &gt; &gt; <br>
        &gt; &gt; <br>
        &gt; &gt; _______________________________________________<br>
        &gt; &gt; seaside mailing list<br>
        &gt; &gt; <a class="ecxmoz-txt-link-abbreviated" href="mailto:seaside@lists.squeakfoundation.org">seaside@lists.squeakfoundation.org</a><br>
        &gt; &gt;
        <a class="ecxmoz-txt-link-freetext" href="http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside" target="_blank">http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside</a>
        <br>
        &gt; &gt; <br>
        &gt; &gt; <br>
        &gt; &gt;
        ------------------------------------------------------------------------<br>
        &gt; &gt; <br>
        &gt; &gt; _______________________________________________<br>
        &gt; &gt; seaside mailing list<br>
        &gt; &gt; <a class="ecxmoz-txt-link-abbreviated" href="mailto:seaside@lists.squeakfoundation.org">seaside@lists.squeakfoundation.org</a><br>
        &gt; &gt;
        <a class="ecxmoz-txt-link-freetext" href="http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside" target="_blank">http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside</a><br>
        &gt; _______________________________________________<br>
        &gt; seaside mailing list<br>
        &gt; <a class="ecxmoz-txt-link-abbreviated" href="mailto:seaside@lists.squeakfoundation.org">seaside@lists.squeakfoundation.org</a><br>
        &gt;
        <a class="ecxmoz-txt-link-freetext" href="http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside" target="_blank">http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside</a><br>
      </div>
      <pre><fieldset class="ecxmimeAttachmentHeader"></fieldset>
_______________________________________________
seaside mailing list
<a class="ecxmoz-txt-link-abbreviated" href="mailto:seaside@lists.squeakfoundation.org">seaside@lists.squeakfoundation.org</a>
<a class="ecxmoz-txt-link-freetext" href="http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside" target="_blank">http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside</a>
</pre>
    </blockquote>
    <br>
  

<br>_______________________________________________
seaside mailing list
seaside@lists.squeakfoundation.org
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside</div>                                               </body>
</html>