Title: Robo TDSD
1Robo TDSD
...a lightning introduction to top-down
structured design
- David Davenport
- Computer Eng. Dept.,
- Bilkent UniversityAnkara - Turkey.
- email david_at_bilkent.edu.tr
2IMPORTANT
- Students
- This presentation is designed to be used in class
as part of a guided discovery sequence. It is not
self-explanatory! Please use it only for revision
purposes after having taken the class. Simply
flicking through the slides will teach you
nothing. You must be actively thinking, doing and
questioning to learn! - Instructors
- You are free to use this presentation in your
classes and to make any modifications to it that
you wish. All I ask is an email saying where and
when it is/was used. I would also appreciate any
suggestions you may have for improving it.
thank you, David.
3Top-Down Structured Design
How many?
Divide Conquer
What is natural?
Split problem into natural pieces then solve
each piece independently
Each piece is simply another problemIf it is to
big to solve directlyapply divide conquer to
it!
Stepwise refinement
4The Wishing Well (first attempt)
- Apply top-down structured design
Split problem into natural pieces solve each
piece independently
140x140x140
150
100x100
Trace it!
5What went wrong?
- Design assumption
- Naïvely assumed that a method always does what it
is supposed to do! - Is it possible to tell Robo to d rect( 50, 100)
and not have the rectangle appear? - A method works properly only if Robo is in the
initial state assumed by the design
Pre-condition
6Pre Post Conditions
- Must ensure pre-conditions satisfied
- Need to know what they are
- So make methods pre-conditions explicit
- How to tell if met in design?
- Need to know post-conditions too
- Either trace (error prone!)
- or make them explicit in method too
7Pre/Post conditions
- Pre-condition
- The required system state prior to execution of
the method, - if it is not actually in this state at run-time,
the method may fail to perform as specified. - Post condition
- The state of the system after execution of the
method assuming that its pre-conditions were met.
8Example
WHAT the method does. All the information needed
to make use of the method
HOW the method works. Only the programmer of this
method need be concerned with this.
9The Wishing Well (second attempt)
Split problem into natural pieces, and
specify them order to do them in
140x140x140
150
100x100
roof
pole
base
Do these pieces done in this order solve problem?
Its impossible to tell! What other information
is needed?
10The Wishing Well (third attempt)
Split problem into natural pieces, and
specify them order to do them in
140x140x140
150
100x100
roof
pole
base
Do these pieces done in this order solve problem?
If no fix If yes go ahead and solve them
11The Wishing Well (third attempt)
12Wishing Well
13Wishing Well
Comments omitted from presentation for
clarity! Also, need ways to tie design code
together better
14The Wishing Well (fourth attempt)
- Try yet again this time utilising existing
methods where possible
140x140x140
150
100x100
3
2
1
roof
pole
base
Do these pieces done in this order solve problem?
No fix by introducing new pieces changing
program
15Your turn!
- Homework... (for lab)
- Rocket