### <== Previous | Contents | Next ==>

## The Programming Environment (cont.)

### Class Browsers (cont.)

Now, let's look at how the guts of a Strongtalk class look. Press on the HTMLView class browser to show the public interface.

The first thing that you will see that is different from other Smalltalk libraries is that the method signatures shown have type annotations. Notice how much easier this makes it to understand the interface. If you open the class header (the first item in the outline), you will see that the instance variables have types, too (and you can imbed comments in the instance variable string, as well). As you can see, type annotations are enclosed in angle brackets (<...>); method return types are preceded by a hat (^). You will get a quick tutorial on the type system later, so don't worry too much about the exact meaning of the types right now.

You can look at method bodies by expanding the method or methods you are interested in. Many different operations on methods and categories are available by right-clicking over a category or method header to get the context menu.

#### A Little Project

To illustrate using the browsers and the type system, we will undertake a very small project: adding a 'forward' button to the browser. I've gone ahead and added almost all the machinery needed for this, but you will need to add two small methods, and add one line to another method (I'll provide the exact text to enter). I've added an instance variable 'forwardURLs', and put some methods that manipulate it in the category private-forward. If you look at the instance variables, you can see clearly that the type of the instance variable is <OrdCltn[URL]>. OrdCltn is just a convenient alias for OrderedCollection, since it is commonly used. Collections are generic, just like View, so we can see easily that this is an ordered collection of URLs, which the type system will enforce for us.

Expand the private-forward category. If you would like to see all the other places that I modified, right click over the #forwardURLs method and select 'Senders'.

The main thing you need to do is add the method that is invoked when the forward command is invoked. Start by adding a new method to the private-forward category, by selecting 'New method' from the category context menu. Then, enter the following text (you can copy and paste using <Ctrl>-C and <Ctrl>-V):

This method uses the #popNextURLOrIfAbsent: method to pop the last forward link off the forwardURLs ordered collection, sets the model of the view to that URL, and then pushes the previous URL onto the history list. If the forward list is empty, the ...IfAbsent: block is invoked instead. I've intentionally put a common kind of Smalltalk bug in this method, to illustrate the type system. Can you see the bug?

Note the type annotations. The argument is a block, whose value type we don't care about, so we can just use <[]> to indicate a block that takes no arguments and produces an Object, by default. We haven't declared a return type for the method, so it defaults to a return type of <Self>, which we could have explicitly written by writing '^<Self>' at the end of the method signature.

### Programming Environment, cont. ==>