1 Advanced Object Oriented Systems (CM0318) Lecture 9 (Last modified Thursday 21st February 2002)
-
Upload
silvia-reynolds -
Category
Documents
-
view
212 -
download
0
Transcript of 1 Advanced Object Oriented Systems (CM0318) Lecture 9 (Last modified Thursday 21st February 2002)
1
Advanced Object Oriented Systems
(CM0318)
Lecture 9
(Last modified Thursday 21st February 2002)
2
In this lecture we shall learn ...
• How to debug Smalltalk code effectively
• How the model-view-controller paradigm is realised in Smalltalk
• How to discover the structure of a currently-executing application
3
Debugging
• To find out how your code is working in Smalltalk is a bit different from in most systems, because:– you are running the debugger within a fully functioning
Smalltalk system
– because of the way many methods, particularly iteration methods, are implemented you often need to step through system code as well as your own
– you can normally trace through code that does screen updates with limited success: often the wrong bits of the screen get updated!
4
Example
• Consider:
#(3 4 5) do: [:i|
Transcript show:
i printString.
Transcript cr]
5
When executed ...
6
Debugger
• Can either proceed, abandon execution or enter the debugger at this point. If you select Debug, confronted with a debugger comprising:– call stack– code pane– panes for inspecting the receiver’s instance vars (left
bottom)– panes for inspecting the temporary variables of a
method (right bottom)
7
Debugger (ctd.)
• E.g. selecting UndefinedObject>>DoIt causes the code that was executed in the workspace to be displayed. You can ‘step’ through methods (execute to completion) or ‘send’ a message (trace execution through the method involved)
8
9Stepping through to where do: is sent
10
‘Sending’ the do: message ...
• End up tracing through the code implementing do:. E.g. just before executing the block for the first time ...
11
12
If we now send the message ...
13
Tracing code
• So to trace code productively using Smalltalk, need to be able to understand the system code too
• It’s a fundamental tenet of Smalltalk that you are expected to be a good code reader!
14
The Model-View-Controller paradigm
View Controller
Model
Dependent
15
MVC (ctd.)
• Models contain data to be displayed• Views display the data• Controllers handle user gestures
• Some Views are pluggable. They:– automatically create a suitable controller to handle user
input
– specify in their creation methods the messages to send to the model to retrieve the data to be displayed, etc.
16
MVC (ctd.)
• A top-level window is represented by StandardSystemView/StandardSystemController. A StandardSystemView will have sub-views, one for each part of the window.
17
Example• Code for PluggableTest to create a single list pane. Class
method:newExample
| model listView1 topView |
model ← self new initialize.
listView1 ←
PluggableListView on: model
list: #extraList
selected: #extraListSelection
changeSelected: #extraListSelection:.
topView ← StandardSystemView new
label: 'Pluggable Test';
minimumSize: 300@200;
borderWidth: 1;
addSubView: listView1.
topView borderWidth: 1.
topView controller open.
18
New PluggableTest methods
extraList
^#('hello' 'world')
extraListSelection
^1
extraListSelection: aNumber
extraIndex ← aNumber
NB: need to define extra instance variable extraIndex
19Screen dump
20
Exploring interactive applications
• To find out how System Browsers work, for example, one starting point is the code;
• another is to break into execution and explore the structure of the System Browser created. <ALT><.>
• This will allow us to inspect the corresponding views and look at super/subviews, at models, etc.
21