<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Tahoma
}
--></style>
</head>
<body class='hmmessage'>
Great! <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 </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"> 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]. ' </div>
<div>which is neither clean nor evolutive.</div>
<div>I wanted to do something like:</div>
<div><br>
</div>
<div> 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"> dynamicTyping :=
('PaperBibli', selectedType) asSymbol.</div>
<div style="text-indent:0px ! important">bibEntry :=
PaperBibli perform: dynamicTyping new.</div>
</div>
<div><br>
</div>
<div>--> 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> </div>
<div><br>
> Date: Fri, 29 Oct 2010 13:56:14 -0300<br>
> From: <a class="ecxmoz-txt-link-abbreviated" href="mailto:andres@lifia.info.unlp.edu.ar">andres@lifia.info.unlp.edu.ar</a><br>
> To: <a class="ecxmoz-txt-link-abbreviated" href="mailto:seaside@lists.squeakfoundation.org">seaside@lists.squeakfoundation.org</a><br>
> Subject: Re: [Seaside] Dynamic typing in smalltalk<br>
> <br>
> Hi Alexandre,<br>
> I guess you could try two approaches:<br>
> <br>
> 1. Just list the classes in a select, so that the first
step is choosing <br>
> the entry. Once you have this you just create the
appropriate class.<br>
> <br>
> 2. Decouple the type of the object from the object itself
(check also <br>
> <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>
> (lets say PaperType) whose subclasses would be Book,
Article, etc. When <br>
> the user selects the type he wants you just set the
object's type. The <br>
> type class is the one that holds the type-specific
information.<br>
> <br>
> HTH,<br>
> Andrés<br>
> <br>
> Alexandre BP escribió:<br>
> > 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>
> > --> 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>
> > I hope that my explanation is clear<br>
> > <br>
> > <br>
> > <br>
> > Date: Fri, 29 Oct 2010 12:24:22 -0400<br>
> > Subject: Re: [Seaside] Dynamic typing in smalltalk<br>
> > From: <a class="ecxmoz-txt-link-abbreviated" href="mailto:sean@monkeysnatchbanana.com">sean@monkeysnatchbanana.com</a><br>
> > To: <a class="ecxmoz-txt-link-abbreviated" href="mailto:seaside@lists.squeakfoundation.org">seaside@lists.squeakfoundation.org</a><br>
> > <br>
> > There are types in smalltalk. Each object has a type.<br>
> > That aside, what are you trying to accomplish with
your example below?<br>
> > <br>
> > On Fri, Oct 29, 2010 at 12:13 PM, Alexandre BP
<a class="ecxmoz-txt-link-rfc2396E" href="mailto:abalonpe@ulb.ac.be"><abalonpe@ulb.ac.be></a> wrote:<br>
> > <br>
> > <br>
> > <br>
> > <br>
> > <br>
> > <br>
> > <br>
> > Hello,<br>
> > 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>
> > var := Class new. var := (SubClass1) message. var :=
(SubClass2) message.<br>
> > <br>
> > 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>
> > <br>
> > Thank you in advance,Regardsalex <br>
> > <br>
> > _______________________________________________<br>
> > <br>
> > seaside mailing list<br>
> > <br>
> > <a class="ecxmoz-txt-link-abbreviated" href="mailto:seaside@lists.squeakfoundation.org">seaside@lists.squeakfoundation.org</a><br>
> > <br>
> >
<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>
> > <br>
> > <br>
> > <br>
> > <br>
> > <br>
> > _______________________________________________<br>
> > seaside mailing list<br>
> > <a class="ecxmoz-txt-link-abbreviated" href="mailto:seaside@lists.squeakfoundation.org">seaside@lists.squeakfoundation.org</a><br>
> >
<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>
> > <br>
> > <br>
> >
------------------------------------------------------------------------<br>
> > <br>
> > _______________________________________________<br>
> > seaside mailing list<br>
> > <a class="ecxmoz-txt-link-abbreviated" href="mailto:seaside@lists.squeakfoundation.org">seaside@lists.squeakfoundation.org</a><br>
> >
<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>
> _______________________________________________<br>
> seaside mailing list<br>
> <a class="ecxmoz-txt-link-abbreviated" href="mailto:seaside@lists.squeakfoundation.org">seaside@lists.squeakfoundation.org</a><br>
>
<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>