[Seaside] Dynamic typing in smalltalk

andres andres at lifia.info.unlp.edu.ar
Fri Oct 29 18:40:20 UTC 2010


As John suggested, your select list would hold the classes, not strings 
or symbols. Is Smalltalk classes are objects themselves, thus you can do 
something like:

html select
    list: PaperType allSubclasses; "#allSubclasses is a message that any 
class can answer. It returns all the subclasses of that class"
    callback: [:cls | actualType:=cls new ];  "Here you send the message 
#new to the class object and create an instance of it"

You can find more information about Smalltalk in general and its 
reflective nature in some of the many free books collected by Stephane: 
http://stephane.ducasse.free.fr/FreeBooks.html.

HTH,
         Andrés


Alexandre BP escribió:
> thanks for your time,Your second solution seems very nice I'll try it as soon as possible.
> The second one however forces me to have a big list of loops that look like '(selectedType = 'Book') ifTrue: [var := PaperBibliArticle new]. ' which is neither clean nor evolutive.I wanted to do something like:
>  dynamicTyping := ('PaperBibli', selectedType, ' new') asSymbol.bibEntry := PaperBibli perform: dynamicTyping.
> OR
>  dynamicTyping := ('PaperBibli', selectedType) asSymbol.bibEntry := PaperBibli perform: dynamicTyping new.
> --> it doesn't work unfortunately ...
> OR:
> As in JAVA:
> PaperBibli bibEntry;
> (when I need it)bibEntry = new PaperBibliArticle;
> Anyway I'll try the second solution which is more elegant.thank you very muchalex
> 
>  
>> Date: Fri, 29 Oct 2010 13:56:14 -0300
>> From: andres at lifia.info.unlp.edu.ar
>> To: seaside at lists.squeakfoundation.org
>> Subject: Re: [Seaside] Dynamic typing in smalltalk
>>
>> Hi Alexandre,
>> 			I guess you could try two approaches:
>>
>> 1. Just list the classes in a select, so that the first step is choosing 
>> the entry. Once you have this you just create the appropriate class.
>>
>> 2. Decouple the type of the object from the object itself (check also 
>> http://www.ksc.com/article3.htm). Thus PaperBibli would know an object 
>> (lets say PaperType) whose subclasses would be Book, Article, etc. When 
>> the user selects the type he wants you just set the object's type. The 
>> type class is the one that holds the type-specific information.
>>
>> HTH,
>>          Andrés
>>
>> Alexandre BP escribió:
>>> 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,...
>>>  --> 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.
>>> I hope that my explanation is clear
>>>
>>>
>>>
>>> Date: Fri, 29 Oct 2010 12:24:22 -0400
>>> Subject: Re: [Seaside] Dynamic typing in smalltalk
>>> From: sean at monkeysnatchbanana.com
>>> To: seaside at lists.squeakfoundation.org
>>>
>>> There are types in smalltalk. Each object has a type.
>>> That aside, what are you trying to accomplish with your example below?
>>>
>>> On Fri, Oct 29, 2010 at 12:13 PM, Alexandre BP <abalonpe at ulb.ac.be> wrote:
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> Hello,
>>> 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:	
>>>       var := Class new.	var := (SubClass1) message. 	var := (SubClass2) message.
>>>
>>> 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?
>>>
>>> Thank you in advance,Regardsalex 		 	   		  
>>>
>>> _______________________________________________
>>>
>>> seaside mailing list
>>>
>>> seaside at lists.squeakfoundation.org
>>>
>>> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
>>>
>>>
>>>
>>>
>>>
>>> _______________________________________________
>>> seaside mailing list
>>> seaside at lists.squeakfoundation.org
>>> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside 		 	   		  
>>>
>>>
>>> ------------------------------------------------------------------------
>>>
>>> _______________________________________________
>>> seaside mailing list
>>> seaside at lists.squeakfoundation.org
>>> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
>> _______________________________________________
>> seaside mailing list
>> seaside at lists.squeakfoundation.org
>> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
>  		 	   		  
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> seaside mailing list
> seaside at lists.squeakfoundation.org
> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside


More information about the seaside mailing list