Send to Printer


ST 4U 348: Reflecting on Class Names

February 22, 2013 0:49:38.922

Today's Smalltalk 4 You looks at the common way to look up Smalltalk class names (things differ a bit in VisualWorks and ObjectStudio). If you have trouble viewing it here in the browser, you can also navigate directly to YouTube. To watch now, click on the image below:

Class Lookups.

If you have trouble viewing that directly, you can click here to download the video directly. If you need the video in a Windows Media format, then download that here.

You can also watch it on YouTube:

Today we'll continue looking at reflection in Smalltalk. In most Smalltalk implementations (Cincom Smalltalk being the exception), there's one namespace (Smalltalk). Thus, looking up a class by name is simple:

clsName := 'Person'.
cls := Smalltalk at: clsName asSymbol.
^cls new.

That makes reading in data from a source (a file, for instance) that includes class names pretty easy - get the class name, create an instance, and then dump data in the variables as it's found in the file. We'll take a look at that next time.

Need more help? There's a screencast for other topics like this which you may want to watch. Questions? Try the "Chat with James" Google gadget over in the sidebar.

Tags: ,

[st4u348-iPhone.m4v ( Size: 739326 )]

posted by James Robertson

 Share Tweet This