• Aucun résultat trouvé

VIEWING EXISllNG CLASSES

Dans le document til Smalltalk (Page 118-123)

Broy,sers

4.3 VIEWING EXISllNG CLASSES

A system browser provides access to all the relevant information concerning classes within the class library. For example, we can display the following information:

• The definition of a class to determine its instance and class variables.

• The class hierarchy local to a given class to determine its relationship with related classes.

• The class and instance protocol supported by a class.

• The source code for any method.

Information relating to a class is displayed in the text pane of the browser by selecting entries from the list panes and from the various pane menus. What is displayed in a list pane of a browser is related to the selections previously made in neighboring list panes (to the left). The arrows in Fig. 4.2 indicate the dependencies between the panes of the browser.

Selecting a particular class category, for example, displays the classes within that category in the class names pane. Selecting a particular class displays a list of message categories in the message categories pane. The list willbeeither a list of instance message categories or a list of class message categories, depending on the state of the class-instance switches below the class names pane. Next, selecting a particular message category displays the selectors of the methods in that category in the message selectors pane. Finally, selecting a message selector causes the code for that method to be displayed in the text pane at the bottom. Other kinds of information may also be displayed in the text pane; e.g., the definition of a class. We will discuss this in more detail in following sections.

The yellow button menu entries are also dependent on the selections made in the list panes. The menu entries for each list pane in Fig. 4.4 are those displayed when an item from that pane is selected. Fewer or different entries may be displayed if an item is not selected in a pane. Menus in your system may differ slightly from those shown.

In Fig. 4.4, the class category Graphics.Primitives is selected. The class names displayed in the class names pane are therefore the classes in this category. The class Pen is selected and this, together with the fact that the instance menu item is selected, determines that the message categories for instances of class Pen will be displayed in the message categories pane. The message category geometric designs is selected, indicating that the message selectors for instance methods in the category geometric designs in the class Pen are displayed in the message selectors pane. Finally, the selector spiral:angle: is selected, causing the Smalltalk code for this method to be displayed in the text pane.

Orap IC -Dftl~~

Oraphics-Pa ths Oraphics-Views

~plral: n angle: a

"Draw a double squiral directly on the display."

"Display white.

Pen new spiral: 200 angle: 89; home; spiral: 200 angle: -89."

1 to: n do:[:i

I

self go:i;turn: a]

..:..-: : : . Figure 4.4 Browser Pane dependencies.

Chapter 4 Programming with Browsers

!I~

?

~:

:.'::

,.>x:o:::.:.:::,~.~

l

103

4.3.1 Finding a Class

Although classes are organized in a hierarchy, they are displayed in a different manner in a browser. For example, classes associated with graphics primitives are collected together under the category Graphics·Primitives independent of their inheritance structure. From the point of view of a user, classes are categorized into sets of functionally related classes.

Even so, finding a class within the system can be frustrating for the beginning Smalltalk programmer. It is not likely that you will know the category of the class you are looking for - considerable time can be spent searching through the class categories. A fast way of finding the category for a class is to send the class a category message. For example, evaluating the expression

Pen category

in a workspace returns the category Graphics-Primitives. This class category can be easily found by scrolling the class category pane since the pane is sorted alphabetically.

Alternatively, some Smalltalk systems have a find class entry in the yellow button menu of the class categories pane. Selecting this menu entry invokes a prompter that asks for the name of the class to be located. When the class name is entered, the required class category is automatically selected in the browser. Additionally, operation find class is useful when the spelling or the exact name of a class is unknown. Typing a pattern string using the character'*' as a wild card character brings up a menu of classes matching the pattern. For example, in Fig. 4.5, the pattern p* is entered in the find class prompter. As shown in Fig. 4.6, a menu of class names beginning with the letter P will be displayed. Selecting one causes the browser to position itself at that class.

Activate a System Browser and browse through the class library. In particular, lookfor each of the following classes: Date. Integer, Spline. Quadrangle. Bag, and Character. If thereisno find class facility. you will need to interrogate the system to find the category of each class.

If thereisafind classfacility,lookfor classes that end in "View", "Controller", or "Collection".

4.3.2 Viewing Class Definitions

To display the definition of a class in the text pane of a browser, proceed with the following four steps:

Select the class category from the class categories pane.

Select the class from the class names pane.

Set the instance-class switches to instance.

Select definition from the yellow button menu of the class names pane.

Fig. 4.7 shows the definition of class Pen. The definition displays the class name, the name of the superclass, instance variables, class variables, pool dictionaries, and the class category. Note that selecting definition when the instance-class switches are set to class

displays the definition of the metaclass1for Pen; Le., the definition of the class for which class Pen is an instance.

PA

tion direction penD own ' pooIOictionarie:;;: ..

category: 'Oraphics-Primitives'

:.::

Ii:

!~

~:

'0'x::.:.." ::; :..:.: § Figure 4.5 Searching for class names matching the pattern ·P*'.

Oraphics-Display Oraphios-Pa ths Oraphios-Views

Paragraph ParagraphEditor

ParseNode Parser

Par;,;;,ok '"",

P.'i~~;:'~:~:~ .. m ~

pr:;::S:S:~:h:~~ler

ction penDo..'m ' I!:!..r.ll.

Project .,.:~

~:j~:~~:~t~~I~;r III

ProjectlconControllet

W

ProjectView

::1

'.>

.>,,~

,:"'X""::;:'.:.,> •

Prot~.c~l~r~.w.se~

,." ..

~>.,<'." x:::::~:::;::~:

..::.·:;;;::;:.*:::::::;:·:·:••

:~:·:~;m.;:;:j:N::l;1

..'~'

.fItBitsubolass: #Pen instanceVariableNam classVariableNames: ' poolDiotionaries: ..

category:

'Oraphics-Figure 4.6 Menu of class names matching the pattern string ·P*'.

IThe role of metaclasses is described in detail in Chapter 6 - classes are objects and therefore must be instances of some class. A class is the only instance of its own metaclass.

Chapter 4 Programming with Browsers 105

...' ':::::::::::@::~~ul'f~II!!~~111

-,,---J '1

~\ ;~

Graphics-Display initialize-release

f

Graphics-Paths accessing

! '~:,:;.:::.,: .. :I-::~l~:"':=':':":'I:_i:_:",:":_:,:,,,,::_:_:s_:",:,#,:,,:p:~:n::

__

:::-:::-C~-I_a:s:s:~_C_O_I_Or_i_ng

...._ _- - - f :

A irlstanceVariableNarnes: 'frarne location direction penDownI

~

classVariableNarnes:II

~1

poolDictionaries: II

I

category: 'Graphic,-Primitive.'

.:::'~:""""'".

Figure 4.7 Definition of class Pen.

Display the definitions of each of the following classes: Date. Integer. Spline.

Quadrangle. Bag.andCharacter.

4.3.3 Viewing the Class Hierarchy

To detennine the inheritance hierarchy for a class, proceed with the following four steps:

• Select the class category from the category pane.

• Select the class from the class names pane.

• Set the instance-class switches to instance.

• Select hierarchy from the yellow button menu of the class names pane.

The class hierarchy is displayed in the text pane and shows the superclass chain above and below the class. In addition, the instance variables for each class in the hierarchy are also displayed. Remember that instances of a class inherit the instance variables of all their superclasses. The set of instance variables for a class consists of all the instance variables in the class itself plus the instance variables of all the superclasses. Selecting hierarchy when class is selected from the instance-class menu displays the hierarchy for the metaclass2of class Pen.

Fig. 4.8 illustrates the inheritance hierarchy for class Pen. Pen is a subclass of class BitBlt, which is itself a subclass of class Object. In addition to its own instance variables, class Pen inherits the instance variables of class BitBIt. Pen has no subclasses.

2 As you may discover by viewing the hierarchy when the class switch is selected. the metaclass hierarchy actually extends above the metaclass for Object. More details are providedin Chapter 6.

Graphics-Oisplay Graphics-Pa ths Graphics-Views

Iltl! :

initialize-release accessing

~~~='I~---I coloring

Dans le document til Smalltalk (Page 118-123)