Lab1


Lab 1: Introduction to Everything


Overview

In this lab, you will do a simple design and programming task -- creating a small hierarchy of objects that have names and can greet you. You will use a program called BOOST to design the hierarchy and generate documentation and skeleton code. You will then use Squeak Smalltalk to add behavior to the classes.

You will create one abstract class called Muppet and two concrete classes called FrogMuppet and GrouchMuppet.

By the end of this lab you should:

Lab Grading Policy

You have until before class on Thursday to turn in this lab. No late assignments will be accepted!

Further Note:

This is a tutorial for running BOOST and Squeak from the NT lab. Complete information on BOOST (including download instructions) can be found at http://www.gvu.gatech.edu/edtech/BOOST/home.html


NOTE IF YOU ARE RUNNING SQUEAK FROM HOME!

The NT version of Squeak is all set up already for filing code out properly. But if you're working from home, you will need to modify your Squeak image in order to turn in your labs.

You will need to "file in" the Squeak file CrLfFileStream.cs into your Squeak directory. Save the file (to do this, right-click on the link to save the file in your directory) and open Squeak. Next, right click on the Squeak desktop and select open..., open file list. Highlight the CrLfFileStream.cs file in your directory and right click on it. Select the fileIn option from the menu. At this point you should have successfully filed in a file into Squeak.

Next, open up the System browser and search for the class FileStream. (Choose Find Class from the categories list menu.) Select the Class button on the browser and select the "concrete classes" protocol. Click on the concreteStream method so that it appears in the text pane. Change the StandardFileStream text to CrLfFileStream and accept the changes. This will modify your squeak image to "file out" more readable code files.

Step One: Starting BOOST

To Run BOOST (from the NT lab):

  1. Open the S: drive from the My Computer window
  2. Open the Apps folder.
  3. Open the BOOST folder
  4. Double click on BOOST.bat

When you start BOOST, you will see a screen that asks you for your name and initials. This information is used on the output files that BOOST generates, so it's in your best interest to be accurate.

After entering that information, you will see the main BOOST window.


Step Two: OOA

BOOST supports you in the Object-Oriented Analysis tasks of creating a list of candidate classes for your design, choosing which classes will actually be in your design, and assigning responsibilites to each class. Since this is just a lab, we don't need to go through the whole brainstorming process.

Creating Classes

Click on the button labled "New..." in the upper left hand corner. A dialog box will come up, prompting you for the name of a new candidate class. This dialog lets you rapidly type in a list of class names.

You now have three candidate classes. To add them to the design, select the class in the list and press "create". The class will show up in the main part of the window, inside a rectangle. To remove the class from the design, select it by clicking on it's rectangle and choosing "Uncreate Class" from the OOA menu.

You can drag the classes around on the screen if you want. Notice that they snap to an invisible grid, to make it easier to line classes up

Adding Responsibilites

In a full design, you would assign responsibilities to each class, as a way of describing the role the class plays in the program without having to describe how it fulfills that role. BOOST allows you to add RC pairs -- the combination of a Responsibility with another class that the class Collaborates with. Here's an example:


Step Three: OOD

BOOST provides support for the Object-Oriented Design tasks of assigning attributes, services and links, and checking the design. You switch to OOD tasks by clicking on the switch in the bottom left of the screen.

Adding attributes and services

The Muppet class will need attributes named "name" and "greeting", and a service called "greet" (it will have other methods, like initialization, that are not considered services). Here's how to add them.

Adding Links

You need to add the gen/spec links that show the Muppet class is the superclass of FrogMuppet and GrouchMuppet. Here's one way to do that.

Back in the window, you can move the classes around to clean up the diagram -- BOOST expects subclasses to be lower in the diagram than their superclass.


Step Four: Generating Output

BOOST allows you to save your design, and generates both HTML and Smalltalk output. Here's a sample.

That's the end of the BOOST section of this lab. For more information on using BOOST, you can read the full documentation at http://www.gvu.gatech.edu/edtech/BOOST/documentation.html


Step Five: Starting Squeak

The First Time You Run Squeak

Do the following to get set up:

  1. If you haven't already, create a directory in your network home directory (drive H:) to keep your 2390 files in, for instance H:cs2390.
  2. Using NT Explorer or My Computer, open S:AppsSqueak
  3. Copy Squeak1.31.image copy Squeak1.31.changes into the directory you made above. To reduce confusion, you can rename the files to reflect that they are your image and changes file, as opposed to the stock 1.31 image and changes file. BE SURE TO MAKE THE IMAGE AND CHANGES FILE NAMES MATCH!. For instance, you would make the following two copies:

To Run Squeak (Every Time)

Here is the (convoluted) procedure for running Squeak on the NT's:

  1. Copy your image and changes file from your home directory to C:Temp
  2. Double click on SqueakXXX.image
  3. If a window appears asking you what to open the file with.. Choose browse and select s:appssqueak.exe
  4. Check the box next to "Always use this program to open this type of file" if you want Windows to always use Squeak to open .image files
  5. When you are done and have saved and quit Squeak, copy your image and changes file back to your home directory, and delete everything you have put in C:Temp.

WARNING: Do not access another student's image and/or changes file that have been left in a temp directory. Doing so will be considered a violation of the honor code.

If you haven't already, go ahead and start up Squeak on your personal image.


Step Six: Basic Usage: The Mouse

Smalltalk uses all three buttons of the mouse extensively. Within a Smalltalk window, the buttons work as follows:

Also, you can left click on the gray background of the Squeak window and get a system-wide menu with options to create new windows and to exit the systems.

Try it now. Left click on the background, hold the button down, select "open", and select "open transcript". An orange window labeled "Transcript" should appear. Use the left button on the borders to shrink this window down a little, and then move it to the bottom of the screen out of the way. This window is where your output will appear later on.

As a second test, left click on the background, hold the button down, and select "save". The cursor should change for a couple of seconds as Squeak saves a current version of your image; if you get an error message, then you are probably using an image on a network drive, instead of in C:Temp; exit Squeak (without saving changes), and try the above directions again.


Step Seven: Creating the Muppet Classes

To create a new class you need to open a System Browser. Click the left button on the gray background area, select "open", and select "open browser". A new window should appear, which has divided into 5 subwindows ("panes"): four panes across the top and one big one at the bottom.


The leftmost pane is a list of categories. Each category contains a bunch of related classes. Create a new category called MuppetProject by clicking the middle button in that pane, choosing "add item", and typing MuppetProject in the prompter window.

The category MuppetProject will be added to the category list, and a template for defining a new class appears. Now, create the Muppet class:

Leave the Object specification alone, so that the superclass of Muppet will be Object.

The result should look something like this:

Object subclass: #Muppet
    instanceVariableNames: 'name greeting'
    classVariableNames: ''
    poolDictionaries: ''
    category: 'MuppetProject'

When you think you have got it, tell Smalltalk to accept the code: click in the text pane with the middle button and choose accept. Assuming you have made no syntax errors, the class should appear in the second pane of the browser. If you have made syntax errors, correct them and try again.

Now create the FrogMuppet and GrouchMuppet classes. What is the superclass of these classes? Do they have any instance or class variables?


Step Eight: Adding Muppet Functionality

Now you will define the behavior of the Muppet class, which will be inherited by the FrogMuppet and GrouchMuppet classes.

The third list in the System Browser is for protocols, which are groups of related methods. Create a protocol for the Muppet class by selecting that class, choosing "add item" by center-clicking in the protocol list, and typing in accessing at the prompt.

A method template will appear in the text pane. To add each new method, you will replace the top line with the message name, place a comment in the double quotes, and insert the text at the bottom. After editing the template for the new method, you accept it to tell Smalltalk to compile it.

Create two methods for accessing the name variable, as follows.

First, create a name method by changing the template in the text pane to look like this:

name
  ^name

Now, use middle-button-menu to choose accept.

Click on name in the rightmost pane, deselecting it, so that the method template reappears. Edit the template to create a new method as follows:

name: aName
  name := aName.

Again, accept it. You now have two methods in the accessing protocol, name and name:.

Create a protocol for initializing, and place the following method inside it:

initialize
  greeting := 'I am an abstract muppet'.

Create a protocol for greeting, and place the following method inside it:

greet
  Transcript cr. 
  Transcript show: greeting; cr.
  Transcript show: 'I am ', name; cr.

Open a workspace to test your code in, using the "open" menu from the background menu. Type the following code into the workspace:

| muppet |
muppet := Muppet new initialize.
muppet name: 'Jim Henson'.
muppet greet.

Select the text with the mouse, click the center button, and choose "do it". Do you get what you expect?


Step Nine: Adding Subclass Functionality

Frogs and Grouches differ from ordinary Muppets in their greeting. For each class create initialization protocols. Create an initialize method for both classes that changes the greeting. The FrogMuppet greeting should be 'Hi Ho', and the GrouchMuppet greeting should by 'Go Away'.

Test your muppets with the following code:

| frogMuppet grouchMuppet |
frogMuppet := FrogMuppet new initialize.
grouchMuppet := GrouchMuppet new initialize.
frogMuppet name: 'Kermit the Frog'.
grouchMuppet name: 'Oscar the Grouch'.
frogMuppet greet.
grouchMuppet greet.


Step Ten: Making the Muppets interact

Now, let's make the muppets interact. Write a method in the Muppet class that:

When you execute the following code:

| frogMuppet grouchMuppet |
frogMuppet := FrogMuppet new initialize.
grouchMuppet := GrouchMuppet new initialize.
frogMuppet name: 'Kermit the Frog'.
grouchMuppet name: 'Oscar the Grouch'.
frogMuppet greetByName: grouchMuppet.
grouchMuppet greetByName: frogMuppet. 

You should see:

Hi Ho, Oscar the Grouch! I am Kermit the Frog!
Go Away, Kermit the Frog! I don't care! I am Oscar the Grouch!

Step Eleven: Turning in the code

You should turn in a fileOut of the code you wrote.

To make the fileout, make sure the MuppetsLab class category is selected in a System Browser, and then choose "file out" from the middle-button menu in class-category pane (the one on the top left). The system will silently create a text file named MuppetsLab.st. Copy MuppetsLab.st to your 2390 directory (on your H: drive).

Mail the file to your TA any way that is convenient. Here is one way to do so:

  1. Select Run from the Start menu and type in:

    telnet lennon.cc

  2. Login to lennon using your CoC login and password.
  3. Change to your 2390 directory, eg cd ~/cs2390 (or wherever you put your code)
  4. Type:

    /usr/ucb/mail -s "TI,Lab1,My SocialSecurity Number or Student Number" cs2390@prism.gatech.edu < Muppet sLab.st

    (Replace My SocialSecurity Number or Student Number with your student number, e.g., 345544545).


News Page | CS2390 Sp'98 Home Page | CS2390 CoWeb | STABLE | BOOST
Questions/comments/concerns to guzdial@cc.gatech.edu
Page last updated 4/8/98; 1:56:31 PM