Title: Structured Problem Solving
1Structured Problem Solving
- The SmallTalk Environment
2The 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
3SummaryThe 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
4Messages
5A New Object
6A New Object
Tony1 is the name of the object. We use this
name to address it.
TonysPie is the label at the top of the Grid.
7Longer Programs
8Longer Programs
Note the full stops at the end of each message.
9Repeating
10Repeating
Note the loop structure 4 timesRepeat
11Repeating
Note the loop contents Message1 . Message2.
Message3 Separated by full stops.
12Creating New Objects
- Identifying Attributes Protocols
13Attributes
- Names for Attributes will
- Begin with a lower case letter
- Contain no spaces
- e.g. customerName
- numberOfRecords
- colour
14Names for Protocols
- Names for Protocols will
- Begin with a lower case letter
- Contain no spaces
- e.g. reserveVideo
- turnRight
- red
15Messages 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
16Messages 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
objects customerName - Customer1 customerName
17Student 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.
18Student Database Attributes
- The database will consist of a class of objects
called student - These objects will have the following attributes
- studentID
- yearofStudy
- currentModule1
- currentModule2
19Student Database Protocol
- changeYear
- adds 1 to the current year
- currentModule1
- changes currentModule1
- currentModule2
- changes currentModule2
- yearofStudy
- requests the current year of study
20Example
- The following messages are sent
- changeYear
- currentModule1 M20001A
- currentModule2 M20002B
- OBJECT Student1
- Class of Object Student
- studentID 12345678
- yearofStudy 2
- currentModule1 M10001A
- currentModule2 M10002B
- Protocol
- changeYear, currentModule1, currentModule2 ,
yearofStudy
21Example
- The following message is sent
- yearofStudy
- The object responds with
- 3
- OBJECT Student1
- Class of Object Student
- studentID 12345678
- yearofStudy 3
- currentModule1 M20001A
- currentModule2 M20002B
- Protocol
- changeYear, currentModule1, currentModule2 ,
yearofStudy