2.4.2Defining a Component
Now we will define a new component named
WebCounter. In Seaside, a “component” refers to any class which inherits from the class
WAComponent (either directly or indirectly).
It is only a coincidence that this class has the same name as its package. Normally packages will contain several classes, and the package names and class names are unrelated.
To start creating your class, click on the
WebCounter package you just created, to ensure that it is selected. The “class creation template” will appear in the source pane of the browser. Edit this template so that it looks as follows:
WAComponent subclass: #WebCounter
Notice that lines 3 and 4 contain two consecutive single quote characters, not a double quote character. We are specifying that the
WebCounter class is a new subclass of
WAComponent. We also specify that this class has one instance variable named
count. The other arguments are empty, so we just pass an empty string, indicated by two consecutive quote marks. The “category” value should already match the package name. Note that an orange triangle in the top-right indicates that the code is not compiled yet.
Once you are done entering the class definition, right-click anywhere in that pane to bring up the context menu, and select the menu item Accept (s) as shown in Figure 5. Accept in Smalltalk jargon roughly means compile.
Once you have accepted, your browser should look similar to the one shown in Figure 6. The browser now shows the class that you have created in the class pane. Now we are ready to define some behaviour for our component.