Structured Problem Solving The SmallTalk Environment
The First Window When this window appears, you are ready to start your Smalltalk session. Do not do anything to the text in this window, it is just information. Click on File – New Workspace
Summary: The SmallTalk Workspace Starting a New workspace: Select File – New Workspace Adding Text: Type in, it is a text editor. Saving:Select File – Save Opening:Select File – Open Executing: Select the Text, right click, Do it
Messages
A New Object
Tony1 is the name of the object. We use this name to address it. Tony1 is the name of the object. We use this name to address it. TonysPie is the label at the top of the Grid.
Longer Programs
Note the full stops at the end of each message.
Repeating…
Note the loop structure: 4 timesRepeat [ ] Note the loop structure: 4 timesRepeat [ ]
Repeating… Note the loop contents [ Message1. Message2. Message3 ] Separated by full stops. Note the loop contents [ Message1. Message2. Message3 ] Separated by full stops.
Creating New Objects Identifying Attributes & Protocols
Attributes Names for Attributes will: Begin with a lower case letter Contain no spaces e.g. customerName numberOfRecords colour
Names for Protocols Names for Protocols will: Begin with a lower case letter Contain no spaces e.g. reserveVideo turnRight red
Messages 1 Each message which sets an attribute value has the structure: attribute:value For example to set a customer name we would send the message: customerName: Tony The message to an object called customer1 would be: customer1 customerName: Tony
Messages 2 Each message which requests an attribute value as a reply should be given the same name as the attribute name. for example: customerName is the message which requests the value of an object’s customerName Customer1 customerName
Student Database A simple database is required to store a student ID number, their year of study and their current modules. We will wish to be able to send messages to the objects to increment the year of study, and change current modules. We will also need to interrogate the object to find out the year of study.
Student Database: Attributes The database will consist of a class of objects called student These objects will have the following attributes: studentID yearofStudy currentModule1 currentModule2
Student Database: Protocol changeYear adds 1 to the current year currentModule1: changes currentModule1 currentModule2: changes currentModule2 yearofStudy requests the current year of study
Example OBJECT: Student1 Class of Object: Student studentID yearofStudy 2 currentModule1 M10001A currentModule2 M10002B Protocol: changeYear, currentModule1:, currentModule2:, yearofStudy The following messages are sent: changeYear currentModule1: M20001A currentModule2: M20002B
Example OBJECT: Student1 Class of Object: Student studentID yearofStudy 3 currentModule1 M20001A currentModule2 M20002B Protocol: changeYear, currentModule1:, currentModule2:, yearofStudy The following message is sent: yearofStudy The object responds with: 3