1 advanced object oriented systems (cm0318) lecture 9 (last modified thursday 21st february 2002)

21
1 Advanced Object Oriented Systems (CM0318) Lecture 9 (Last modified Thursday 21st February 2002)

Upload: silvia-reynolds

Post on 11-Jan-2016

213 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 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)

Page 2: 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

Page 3: 1 Advanced Object Oriented Systems (CM0318) Lecture 9 (Last modified Thursday 21st February 2002)

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!

Page 4: 1 Advanced Object Oriented Systems (CM0318) Lecture 9 (Last modified Thursday 21st February 2002)

4

Example

• Consider:

#(3 4 5) do: [:i|

Transcript show:

i printString.

Transcript cr]

Page 5: 1 Advanced Object Oriented Systems (CM0318) Lecture 9 (Last modified Thursday 21st February 2002)

5

When executed ...

Page 6: 1 Advanced Object Oriented Systems (CM0318) Lecture 9 (Last modified Thursday 21st February 2002)

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)

Page 7: 1 Advanced Object Oriented Systems (CM0318) Lecture 9 (Last modified Thursday 21st February 2002)

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)

Page 8: 1 Advanced Object Oriented Systems (CM0318) Lecture 9 (Last modified Thursday 21st February 2002)

8

Page 9: 1 Advanced Object Oriented Systems (CM0318) Lecture 9 (Last modified Thursday 21st February 2002)

9Stepping through to where do: is sent

Page 10: 1 Advanced Object Oriented Systems (CM0318) Lecture 9 (Last modified Thursday 21st February 2002)

10

‘Sending’ the do: message ...

• End up tracing through the code implementing do:. E.g. just before executing the block for the first time ...

Page 11: 1 Advanced Object Oriented Systems (CM0318) Lecture 9 (Last modified Thursday 21st February 2002)

11

Page 12: 1 Advanced Object Oriented Systems (CM0318) Lecture 9 (Last modified Thursday 21st February 2002)

12

If we now send the message ...

Page 13: 1 Advanced Object Oriented Systems (CM0318) Lecture 9 (Last modified Thursday 21st February 2002)

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!

Page 14: 1 Advanced Object Oriented Systems (CM0318) Lecture 9 (Last modified Thursday 21st February 2002)

14

The Model-View-Controller paradigm

View Controller

Model

Dependent

Page 15: 1 Advanced Object Oriented Systems (CM0318) Lecture 9 (Last modified Thursday 21st February 2002)

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.

Page 16: 1 Advanced Object Oriented Systems (CM0318) Lecture 9 (Last modified Thursday 21st February 2002)

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.

Page 17: 1 Advanced Object Oriented Systems (CM0318) Lecture 9 (Last modified Thursday 21st February 2002)

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.

Page 18: 1 Advanced Object Oriented Systems (CM0318) Lecture 9 (Last modified Thursday 21st February 2002)

18

New PluggableTest methods

extraList

^#('hello' 'world')

extraListSelection

^1

extraListSelection: aNumber

extraIndex ← aNumber

NB: need to define extra instance variable extraIndex

Page 19: 1 Advanced Object Oriented Systems (CM0318) Lecture 9 (Last modified Thursday 21st February 2002)

19Screen dump

Page 20: 1 Advanced Object Oriented Systems (CM0318) Lecture 9 (Last modified Thursday 21st February 2002)

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.

Page 21: 1 Advanced Object Oriented Systems (CM0318) Lecture 9 (Last modified Thursday 21st February 2002)

21