Download presentation
Presentation is loading. Please wait.
1
Structured Problem Solving The SmallTalk Environment
2
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
3
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
4
Messages
5
A New Object
6
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.
7
Longer Programs
8
Note the full stops at the end of each message.
9
Repeating…
10
Note the loop structure: 4 timesRepeat [ ] Note the loop structure: 4 timesRepeat [ ]
11
Repeating… Note the loop contents [ Message1. Message2. Message3 ] Separated by full stops. Note the loop contents [ Message1. Message2. Message3 ] Separated by full stops.
12
Creating New Objects Identifying Attributes & Protocols
13
Attributes Names for Attributes will: Begin with a lower case letter Contain no spaces e.g. customerName numberOfRecords colour
14
Names for Protocols Names for Protocols will: Begin with a lower case letter Contain no spaces e.g. reserveVideo turnRight red
15
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
16
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
17
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.
18
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
19
Student Database: Protocol changeYear adds 1 to the current year currentModule1: changes currentModule1 currentModule2: changes currentModule2 yearofStudy requests the current year of study
20
Example OBJECT: Student1 Class of Object: Student studentID 12345678 yearofStudy 2 currentModule1 M10001A currentModule2 M10002B Protocol: changeYear, currentModule1:, currentModule2:, yearofStudy The following messages are sent: changeYear currentModule1: M20001A currentModule2: M20002B
21
Example OBJECT: Student1 Class of Object: Student studentID 12345678 yearofStudy 3 currentModule1 M20001A currentModule2 M20002B Protocol: changeYear, currentModule1:, currentModule2:, yearofStudy The following message is sent: yearofStudy The object responds with: 3
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.