Smalltalk organizes instance behaviors using classes. A class is an object that 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
...
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:
Number
is a subclass of Magnitude
.
This means
Number
is a kind of specialized Magnitude
.
#subclass:instanceVariableNames:classVariableNames:...
was sent to Magnitude
to create this class.
subclass:
argument Number
is prefixed
with “#”. It is a symbol, a kind of unique string. Indeed when
declaring the Number
class, the system does not know about it
yet, so it is named as a symbol.
instanceVariableNames:
argument is a string:
the instance variables of the class are declared by names separated
by a space. There are none in this class definition.
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
itself14. Clicking the arithmetic
category
directly gives access to related methods in the next and last pane at
the right.
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 withString
.
How many methods are there in the arithmetic method category of the
CharacterSequence
class?
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:
2 class
and print
with Ctrl-p,
SmallInteger
is printed and automatically highlighted as the current selection,
SmallInteger
class with Ctrl-b,
SmallInteger
, ready to
be explored.