1 / 15

Robo – TDSD

Robo – TDSD . ...a lightning introduction to top-down structured design. David Davenport Computer Eng. Dept., Bilkent University Ankara - Turkey. email: david@bilkent.edu.tr. IMPORTANT…. Students…

blithe
Download Presentation

Robo – TDSD

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Robo – TDSD ...a lightning introduction to top-down structured design David Davenport Computer Eng. Dept., Bilkent UniversityAnkara - Turkey. email: david@bilkent.edu.tr

  2. IMPORTANT… • 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.

  3. Top-Down Structured Design • In essence… 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

  4. base pole wwell roof f( 150) d rect( 100, 100) d base d pole d roof d equtri(140) 3 2 1 roof pole base The Wishing Well (first attempt) • Apply top-down structured design 140x140x140 Split problem into natural pieces solve each piece independently 150 100x100 Trace it!

  5. Program is a sequence of methods What 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

  6. Pre & Post Conditions • Must ensure pre-conditions satisfied • Need to know what they are • So make method’s 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

  7. Pre/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.

  8. rect // Draws a rectangle of specified // height & width aligned north/south // Params: a – width, b – height // PreCond: in drawing mode, facing north // bottom-left of rectangle // PostCond: as precond and rect is drawn // Author: David // Date: Sept. 2002 f(b) // draw left side r(90) f(a) // draw top r(90) f(b) // draw right side r(90) f(a) // draw bottom r(90) Example • The complete rect method 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.

  9. 140x140x140 150 3 2 1 100x100 The Wishing Well (second attempt) • Try again… 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? It’s impossible to tell! What other information is needed?

  10. 140x140x140 150 3 2 1 100x100 Pre-cond. Post-cond. The Wishing Well (third attempt) • Try again… 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

  11. 140x140x140 150 100x100 150 100x100 2 1 roof pole base pole base 3 3 2 2 1 1 Change post-condition of pole 140x140x140 4 3 140x140x140 150 100x100 roof Pre-cond. Add a new piece to match post-condition of pole to pre-condition of roof roof pole base Post-cond. Change pre-condition of roof The Wishing Well (third attempt) • Possible solutions…

  12. 140x140x140 150 100x100 1 2 1 100x50 150 pole base 100x100 140x140x140 2 4 100x100 3 roof Add a new piece to match post-condition of pole to pre-condition of roof 100x50 3 Wishing Well • First: Top-Down Design

  13. wwell roof pole base d base d pole r( 90) d roof l( 90) f( 70) r( 120) f( 140) r( 120) f( 140) r( 120) f( 70) f( 150) // move to bottom-left l( 90) f( 50) l( 90) f( 100) r( 180) d rect( 100, 100) // move back r( 90) f( 50) l( 90) f( 100) Wishing Well • Then: Implement Comments omitted from presentation for clarity! Also, need ways to tie design & code together better

  14. wwell wwell d base d pole d roof d base d movetopole d pole d movetoroof d roof 4 5 2 3 1 100x50 70 movetopole movetoroof The 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

  15. 250 x 250 x 250 250 x 250 50 x 50 50 x 100 100 x100 x 100 50 x 50x50 300 100 200 Your turn! • In class…? • House • Homework... (for lab) • Rocket

More Related