2.5 A brief introduction to the system Browser

Smalltalk organizes instance behaviors using classes. A class is an object which holds a set of methods to be executed when one of its instances receives a message that is the name of one of these methods.

The System Browser, in short the Browser, is a tool to rule all the classes in Cuis-Smalltalk. It is both a tool to explore the classes (system or user ones) and to write new classes and methods.

To access the tool ...World menu → Open...Browser...

ch02-browserDetailed

Figure 2.1: The System Browser

At the top left are the class categories, groups of classes sharing the same theme. A category can also be used to create a Package, which is an organisational element to save code in a file system. In Figure 2.1, the selected class category is Kernel-Numbers, a group of classes we already started using. The term Kernel- indicates it is part of fundamental categories, but it is only a convention. See the other categories such as Kernel-Text and Kernel-Chronology related to text and date entities.

Next to the right are the classes in the selected class category. They are nicely presented in a parent-child class hierarchy. When a class is first selected in this pane, its declaration appears in the large pane below, the Number class declaration is:

Magnitude subclass: #Number
   instanceVariableNames: ''
   classVariableNames: ''
   poolDictionaries: ''
   category: 'Kernel-Numbers'

A few important points in this declaration:

A subclass inherits behaviors from its parent superclass, and so only needs to describe what is different from its superclass. An instance of Number adds methods (which define behaviors) unknown to an instance of Magnitude. We will explore this in detail as we go forward.

To learn about the purpose of a class, it is good practice to always visit the class comment. Often a comment also comes with code examples to learn how to use the object; these code snippets can be selected and executed in place as done from a Workspace. In Figure 2.1, see the comment button to read or to edit the comment of the selected class.

To the right of the class panel is the method categories panel. A class may have many methods, so grouping them by category helps other users orient themselves in finding related methods. As a reference, Number has more than 100 instance side methods implemented in itself13. Clicking the arithmetic category directly gives access to related methods in the next and last pane at the right.

 note A right click on the Class Category pane brings up its context menu. You can select find class .. or, as the menu indicates, use Ctrl-f (Find), to get a fill-in panel and type part of a class name to match. Try it with String.

 CuisLogo How many methods are there in the arithmetic method category of the CharacterSequence class?

Exercise 2.3: Count of methods

In the Browser, once a method is selected – as in Figure 2.1, abs method – the bottom part shows its source code, ready to be explored or edited. Often, you will find a small comment just after the method name, surrounded by double quotes.

Every object knows its own class and will respond with it when sent the message #class.

Tip. In the workspace Ctrl-b (Browse) on the class name will open a Browser on the named class:


Footnotes

(13)

When considering its parents, the combined method count is more than 300.