Cincom

Primer : The System Browser (Part 1)


In the VisualWorks development environment, the System Browser allows you to view and edit the major components (namespaces, categories, classes, protocols, methods and parcels) of the Smalltalk image. The "image" is the actual file (with the "im" extension) that contains these components.

This primer gives a brief description of what the System Browser does and an example of why it is so powerful.

The following exercise is designed purely to show how the four panes across the top of the System Browser work.
Refer to Figure B-1.


Figure B-1. How the System Browser is organized

The first pane is a list of Categories. Scroll through the list until you find Magnitude-General and click (select) it. Note that in the next pane, a list of five classes appear:

·  Character

·  Date

·  Magnitude

·  Time

·  TimeZone

This (obviously) is the Class pane. Now click (select) Date. Note that in the third pane is a list of Protocols. The list will vary depending on which tab above the pane is selected. Click the Class tab. A list of four protocols will appear:

·  class initializtion

·  general inquiries

·  instance creation

·  private

Click (select) the instance creation protocol. Note that in the next pane, a list of six methods will appear.

·  fromDays:

·  newDay:month:year:

·  newDay:monthNumber:year:

·  newDay:year:

·  readFrom:

·  today

Click (select) the today method. Note that some text will appear in the bottom pane. This is the actual source code for the today method of the Date class.

Having followed the above instructions, you should see a window that looks like below.


Figure B-2. The today method of the Date class

Now click
the Instance tab above the protocol list. Note that the list of protocols has changed. You are now looking at the Instance-side methods for the Date class.

To help you differentiate between the two types of methods, do the following.

1. Open a new Workspace
2. Enter the following code

Date today

3. Highlight (select) all the code, <Operate-Click> and select Print it.

Next to the code, "today's" date should have appeared.

4. Now enter the following code

Date addDays: 1

5. Highlight (select) all the code, <Operate-Click> and select Print it.

A dialog box should have appeared (see below).


Figure B-3. The Notifier dialog box

The reason you got this is because the addDays: method requires an instance of the Date class, not the Date class itself. The today method worked fine on the Date class because it was a class-side method. addDays: is an Instance-side method.

6. Close the Notifier dialog box.

7. Now enter the following code

Date today addDays: 1

8. Highlight (select) all the code, <Operate-Click> and select Print it.

Next to the code, "tomorrow's" date should have appeared.

9. Now enter the following code

Date tomorrow

10. Highlight (select) all the code, <Operate-Click> and select Print it.

Note that a small dialog box appears asking you to proceed, correct it or cancel. When you click the proceed button, the Notifier dialog box appears again. The explanation here is simple: there is no such method called tomorrow for the Date class. But guess what? You can change that. And the way you change that is with the System Browser. Here's how.

11. Click the Class tab above the protocol list. The list of four protocols will return.

12. Click (select) the instance creation protocol. A list of six methods will appear with today being the last in the list.

13. Click (select) the today method. You should now see the source code for the today method.

14. In the method code area, replace all the text that you see with the following:

tomorrow
^self today addDays: 1

15. Now <Operate-Click> in the bottom pane and select Accept. This will "compile" the code you just entered and barring any typos, the tomorrow method will appear in the list of class-side methods for the Date Class.

You should see a window like the one below.

Figure B-4. Our new class-side tomorrow method

16. Now enter the following code in your Workspace

Date tomorrow

17. Highlight (select) all the code, <Operate-Click> and select Print it.

Next to the code, "tomorrow's" date should have appeared.

Summary

If you followed the exercise above, you have learned how categories, classes, protocols and methods are related. The System Browser allows you to see these relationships. You also saw the difference between class-side methods and instance-side methods.

Finally, you used the functionality of the System Browser to create your own class-side method for the Date class. You may not have realized the impact of what you just did but believe it or not, it was most profound, something that has had an incredible amount of appeal to those who program in Smalltalk.

In VisualWorks Smalltalk, you have access to the ENTIRE library of existing (delivered) methods and classes. Not only do you have the ability to create your own classes and methods, but you may also modify existing ones. You have complete control of your Smalltalk development environment. Not many other languages can boast that claim.