• Aucun résultat trouvé

Browsing by Category, Class, Message Category, and Message

Dans le document til Smalltalk (Page 139-146)

IIiIIIiII class

4.6 SPECIAUZED BROWSERS

4.6.1 Browsing by Category, Class, Message Category, and Message

Category, class, message category, and message browsers are browsers that limit access to specified categories, classes, message categories, and messages respectively. They are simply limited access system browsers.

A category browser provides access only to the classes within a specified category. In all other respects, they provide the same functionality as system browsers. A category browser may be opened from a system browser as follows:

Select the class categorytobe browsed.

Select spawn (sometimes labelled browse) from the yellow button menu of the class categories pane.

Frame the class category browser.

Fig. 4.24 illustrates a category browser on the class category Graphics-Primitives.

Notice that a category browser has the same structure as a system browser except that the class categories pane is missing.

A class browser limits access only to a specified class. In all other respects, it provides the same functionality as a category browser. A class browser maybeopened from a system browser or a category browser as follows:

Select the class to be browsed.

Select spawn (sometimes labelled browse) from the yellow button menu of the class names pane.

Frame the class browser.

Fig. 4.25 shows a class browser on class Pen.

Chapter 4 Programming with Browsers 123

frame coloring

moving

geometric designs accessing

initialize-release

-t1rame ,: Point

.;! QuadI'angle Rectangle

:~::~n I

.::§

::~~~;orm:

'I...:i..

:':~

m·:i~'ili~).j;f~-!gAili;=-I[~c~la~s~s:J L-:-:-:-~-~-:-:-:-:-:-:-:...---J!

I

lrame

~l

"Answer the rectangle in which the receiver can draw,"

II

:::::

i

:::~

-:" ••:...>•••••••'::"':'x:::g::::::::~:::~m:::::::~g::::::::::::~~t::::::::::::~::::::::::~~::~:~:::~:::::::~~:::::g~:::::::::::::::::~::::::::::::::::::::::::::::::::~:::::~~§

Figure 4.24 Category Browser on the category 'Graphics-Primitives'.

instance

go:

goto:

home down moving

geometric designs accessing

coloring

---~

~~~~~

~:i:~

lilll

u_---t::::~

, Rown "Set the ,tate01 the reoeiver', pen to down (drawing)."

I

~

...!.:::l::.:: penDown

~

true

I~

~ I

!! ;<-: •••<-;.>:.;.,:•••:.:.;•••• ,.h ••• • ••

,."';'>:'~~~"*"':';':"':"

..•.. ""',«' .. ,,' "',., •·..

·<·"*:;:;:;:m;S~~$~l~"";Wmmx~sl;:;:::lJ

Figure 4.25 Class Browser.

Finally, there are two other seldom used types of browsers: message category browsers, which limit access to a specified message category within a class, and message

1 Inti '

browsers, which allow only a single method to be viewed. A message category browser or message browser may be opened from a browser as follows:

• Select the message category or message to be browsed.

• Select spawn (sometimes labelled browse) from the yellow button menu of the message category or message selectors pane respectively.

• Frame the class browser.

Fig. 4.26 shows a message category browser on the message category moving of class Pen. Fig. 4.27 shows a message browser for the instance message with selector go: in class Pen.

Open the following specialized browsers:

A Category Browser on class category Nwneric-Numbers.

A Class Browser on class Fraction.

A Message Category Browser on category 'converting' in class Fraction.

A Message Browser on method 'asFloat' in category 'converting'.

movmg go:

goto:

home north place:

turn:

~o:distance

"Move the receiver in its current direction a number of bits equal to the argument, distance. If the pen is down, a line will be drawn using the receiver's form source as the shape of the drawing brush,"

I

dir

I

direction=0 ifTrue: [1'Self goto: location+(distance@ 0)].

direction=90 ifTrue: ['tself goto: location+(0@distance)], direction=130 ifTrue: ['tself goto: location - (distance @ 0)].

direction

=

270 ifTrue: ['tself goto: location - (0@ distance)].

dir ~direction degreesToRadians.

dir ~ dir cos@ dir sin.

self goto: dir '" distance+location

'. ..' .~..

Figure 4.26 Message Category Browser.

Chapter 4 Programming with Browsers 125

~: go:

$',:

j ;0' dl~~:~~

the receiver in i" current direction a number of bi" equal to ::: the argument) distance. Ifthe pen is down) a line will be drawn

I

using the receiver's form source as the shape of the drawing bru::;h."

,: I

dir

I

::: direction=0ifTrue: [l'self goto: location + (distance@ 0)]. !

:i: direction=90ifTrue: [l'self 90to: location +(0@distaflce)].

J

:i: direction=180 ifTrue: [Helf 90to: location - (distance@ 0)].

!~~

:~

..::1..:..1...:. direction=270itTrue:[of·self goto: location - (O@distance)].\11

dir ~ direction degreesToRadians. :::~

dir

~

dir cos @ dir sin. :11

i·;!:!l;..m..!.

m';'ls!~.lmfm~l~m~;~m:'I~i!rm.~~.~!i.~m~,am.!~I.cm

..e;

m+;lm~mcm~I.~.im.~;~m.

m;.m,.;..m.. ;"m.I··m·..;..I·!.. m.. m·.·.·m.·.·!·.,·m.·,·.·;:·:·:'!!.·,:!·,.,.m·.·.,I·.,I.·.<!

;.~

..I"..!

!d .)1

Figure 4.27 Message Browser.

4.6.2 Browsing the Superclass Chain

Class hierarchy browsers5are organized around the class hierarchy rather than around class categories. They are particularly useful when trying to view the full protocol supported by a class or when adding and debugging new subclasses. They expedite the viewing of classes in the superclass chain - remember that a class inherits both representation and methods (unless overridden) from its superclasses. The definition of a class, therefore, should not be viewed in isolation. To get the full picture, we must also consider its superclasses. A class hierarchy browser simplifies browsing the classes in the superclass chain of a specified class.

In structure and functionality, class hierarchy browsers are similar to category browsers, except that the classes displayed include only the superclasses and subclasses of a specified class rather than the classes in the category of the class. A class hierarchy browser may be opened as follows:

Select the class to be browsed.

Selectspawn hierarchyfrom the yellow button menu of the class names pane.

Frame the class browser.

Fig.4.28 shows a class hierarchy browser on class Integer.The class names pane contains class Integer, superclasses Number, Magnitude, and Object, along with subclasses LargeNegativeInteger, LargePositiveInteger,andSmallInteger.

5Note that hierarchy browsers are not supported by Version 1 Smalltalk.

Integer Hierarchy

Smalllnteger

LargeNegativelnteger LargePositivelnteger

g;:~N~u-m~b-e-r=====9arithmetic testing comparing

truMation and round 0

enumerating

f actorization and divisi B!!!!!!!!!!!!!!!!!!!!!!!!!!!!!_----I_ class bit manipulation

Number subclass: #Integer instanceVariableNames:II

classVariableNames:II

poolDictionaries:~

category: 'Numeric-Numbers'

Figure 4.28 Class Hierarchy Browser.

Use a Class Category Browser to answer thefoUowing queries:

What is the exact representation ofinstances of class Quadrangle?

What methods are inherited by class Quadranglefrom class Rectangle?

4.6.3 Browsing Selected Sets of Methods

Message·set browsers allow the programmer to browse a collection of methods that share some common characteristic; e.g., methods for the set of messages sent by a specific method. Since the messages selected cut across class boundaries, message selectors are uniquely identified by listing them together with their respective class names. Message-set browsers are important programming and debugging tools. We briefly describe some of their most important uses.

Browsing the Set of Methods that Send a Particular Message

An excellent way to understand how to use a message is to examine methods that already use it. A message-set browser on the set of methods that send a particular message can be created as follows:

Select (in a browser) the method whose use is to be examined.

Select senders from the yellow button menu of the message selectors pane.

Frame the message-set browser.

Chapter 4 Programming with Browsers 127

Fig. 4.29 shows a message set browser created on the class method with selector from User in class Rectangle. Alternatively, the same message-set browser could have been created by evaluating the following expression (see the System Workspace for a template).

SmalltalkbrowseAIICallsOn:#fromUser

Circle cl,3.SS exampleTwo FlillnTheBlank class example3

Form class exampleSpaceFill

!'

FormEditor class tormFromDisplay ji

l

',: FormView cl.3.sS exampleOne:: ~:~:

", FormView class exampleTwo '"

~ll-e-x-a-rr-I'~T~le""lr~!'""""t-h-is-e-x-a-r-",,-p-le-b-y-C-h-O-o-si-n-g-m-en-u-c-o-m-m-a-n-d-p-r-in-t-j-t'-' ----II

: ~;I:::~xamPI'3." I

:-=-:-:.,,,,.:1

Figure 4.29 Message-set Browser on senders of fromUser.

Note that the message-set browser is created on the selector of the message. The browser will therefore contain references to the use of any method with that selector. Since the same selector may be used by any number of classes, some of the references in a message-set browser may not be to the method under scrutiny. For example, the message-set browser created in Fig. 4.29 contains references to the use of method fromUser in class Form as well as class Rectangle.

Use a Message-set browser to answer the following query: which methods send the message with selector 'go:'?

Browsing the Set of Methods that Implement a Particular Message

It is often useful to browse through the implementations of methods with a given selector.

A message-set browser on the set of methods that implement a particular message can be created as follows:

Select (in a browser) any method with the selector whose implementations you wish to examine.

Select implementors from the yellow button menu of the message selectors pane.

Frame the message-set browser.

Earlier in this chapter, we suggested browsing through the system to look for classes that had examplel methods associated with them. The aim was to examine and evaluate the examples to learn about the capabilities of the classes in the system. A more convenient method of finding the examplel methods would be to create a message-set browser on all implementors of examplel. An alternative way to create a message-set browser on all classes that have examplel methods (see Fig. 4.30) would be to evaluate the following expression (see the System Workspace for a template).

SmalltalkbrowaeAlllmplementoraOf: #example1

DisplayTextView class example1 FlllinThe81ank class example"1

lxample1

"Example waits for you to click red button somewhere on the screen. The view will show where you point, Terminate by choosing menu command accept,"

FilllnTheBlank

message: 'What is your name'?' displayAt: Sensor waitButton centered: true

action: [:answer

I

Transcript cr; show: answer]

initialAnswer: "

"FilllnTheBlank example1."

Figure 4.30 Message-set Browser on implementors of example1.

Use a Message-set browser to answer the following query: which classes implement the message with selector 'at:put:' ?

Browsing the Set of Methods that Are Sent in a Particular Method

When trying to understand the implementation of a method, it is often useful to browse the methods for messages sent by the method under study. A message-set browser on the implementors of a particular message sent within a method definition can be created as follows:

Select (in a browser) the method whose implementation is under study.

Select messages from the yellow button menu of the message selectors pane.

Chapter 4 Programming with Browsers 129

• From the message selector menu, choose the selector to be investigated.

• Frame the resulting message-set browser on all implementors of the selector.

Suppose we were viewing method + in class Point. Selecting messages from the yellow button menu of the message selector pane displays a menu containing the selectors used by + (see Fig. 4.31). Selecting asPoint from the menu, for example, opens a message-set browser on all implementors of asPoint (see Fig. 4.32).

y arithmetic accessing comparing

Dans le document til Smalltalk (Page 139-146)