Send to Printer

st4u

ST 4U 243: Extending a Class in VA Smalltalk

June 8, 2012 10:34:25.425

Today's Smalltalk 4 You shows you how to extend an existing class in VA Smalltalk without changing the owning Application. In VA/Envy, all classes are owned by an Application. If you change the class definition or an existing method, you have to change the owning Application. Today we'll look at adding new methods to existing classes in your own Application. 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:

Extensions.

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 look at how to extend existing classes in VA Smalltalk - organizing that code into your own Application/SubApplication instead of in the owning one. We've created a new Application and class, and a single method: #isFoo:

Example

If you imagine this method as the kind of test that will be used to find out whether a given object is a "foo sort of thing" or not, then you see that we want a matching method like this:


isFoo
    ^false

In Object. However, we don't want to add that method to the Application that owns Object. Recall that in ENVY, class definitions are owned by the Application they are defined in. If you need to change and existing method or class definition, you have to create a new version of that Application. However, that's not the case if you merely want to add a new method

In your Application, select the "Classes" menu. Pull down to "Add", and you'll see "Extension" as a possibility. That's what we'll do here:

Extension

You'll then get prompted for the class you want to extend:

Extension

Finally, add the method in the browser - you've now extended a class owned by a different Application in your own Application:

Extension

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.

Technorati Tags: , ,

Enclosures:
[st4u243-iPhone.m4v ( Size: 2600760 )]

posted by James Robertson

 Share Tweet This