Mapping Silverlight Classes to Smalltalk
December 16, 2010
There are two basic types of objects in Silver Smalltalk.
First, there are Smalltalk objects which are created from Smalltalk classes. For example, “MyClass new” would create a new instance of the class MyClass.
Second, there are the native Silverlight objects which are written in a .Net language such as C#.
There is also a third type of object which is a hybrid of the two basic types: the “mapped” object.
A mapped object has the underlying behavior of a native Silverlight object but you can add Smalltalk methods, instance variables, and class variables to it.
An example is the “UserWindow” class which “maps” the underlying “UserWindow” type in Silverlight. You can use the ClassBrowser to browse the hierarchy of classes:
All the window classes (WorkspaceWindow, TranscriptWindow, etc) are derived from “Window”.
It is very useful to be able to map native classes this way. One advantage is speed – in the case of “UserWindow” there is a lot of handling of mouse movements which is best done in compiled C#. And another advantage is that you can libraries that were created in any of the .Net languages like C# or VB.Net.
And because the mapped classes now have Smalltalk attributes as well, you can add methods, instance variables and class variables to them. In the classes derived from “Window”, I have added instance variables for “leftPane”, “rightPanel”, “topPanel”, “bottomPanel”, etc.
In summary, “mapped” classes give you all the speed of C# and the ability to use any C# or VB.Net library. But they behave like Smalltalk classes as well, so they can be customized and extended.
The best of both worlds.