Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "1 Advanced Object Oriented Systems (CM0318) Lecture 9 (Last modified Thursday 21st February 2002)"— Presentation transcript:

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

2 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 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 4 Example Consider: #(3 4 5) do: [:i| Transcript show: i printString. Transcript cr]

5 5 When executed...

6 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 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 8

9 9 Stepping through to where do: is sent

10 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 11

12 12 If we now send the message...

13 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 14 The Model-View-Controller paradigm ViewController Model Dependent

15 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 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 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 18 New PluggableTest methods extraList ^#('hello' 'world') extraListSelection ^1 extraListSelection: aNumber extraIndex ← aNumber NB: need to define extra instance variable extraIndex

19 19 Screen dump

20 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. This will allow us to inspect the corresponding views and look at super/subviews, at models, etc.

21 21


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

Similar presentations


Ads by Google