Lecture 8 Structured Design for Methods and Modules

Constructs naturally result in well structured code

This preview shows 9 out of 17 pages.

constructs, naturally result in well-structured  code Exception: go-to’s, which allow the construction  of arbitrary (possibly bad) structures.  Unavoidable use of goto’s may occur in some  cases, such as in use of assembly language But we can still construct well–structured code if we  follow the SP guidelines 01/08/11 Copyright William. E. Howden 9
Image of page 9

Subscribe to view the full document.

The Psychology of  Structured Programming Even programmers have limited intellectual  capabilities What does the mind find easy, when trying to  read and comprehend? sequencing, alternation, and iteration control flow stacks for non-linear flow while trying to read a linear text, we can use a stack to  remember where we were when we have to go down a level due  to nesting.  When finished, pop the mental stack to go back to  where we were. 01/08/11 Copyright William. E. Howden 10
Image of page 10
Top-Down Design TD is a kind of structured programming  strategy Abstract function/procedure at top level More detailed functions at next level More detailed functions at next  level etc. This “refinement process” continues until  everything is concrete source code At each level only SP constructs are used 01/08/11 Copyright William. E. Howden 11
Image of page 11

Subscribe to view the full document.

Copyright W. Howden 12 DS PseudoCode  and Program Refinement 1 Member Data getADate(DaterPreferences daterPrefs) {     Record record; Boolean match = false; record = filemanager(“getFirst”); see if record matches daterPrefs and set match while ((record =/ null) and (match == false)) {      record = filemanager(“getNext);      see if record matches daterPrefs and set match } if (match = = false) return null else return record; }
Image of page 12
DS PseudoCode  and Program Refinement 2 Next level down, refine the following into  less abstract prose and actual code, or all  actual code see if record matches daterPrefs and set  match see if record matches daterPrefs and set  match 01/08/11 Copyright William. E. Howden 13
Image of page 13

Subscribe to view the full document.

Structured Programming and  Object Oriented Design Can be applied to class methods In a procedural program, e.g. in C,  procedures may be much larger than the  average method, so SP may be more  critical 01/08/11 Copyright William. E. Howden 14
Image of page 14
Architectural Design Components and Relationships Component Separately defined collection of  procedures/methods/functions and/or data  definitions Varies by programming language Early programming languages: single  procedure 01/08/11 Copyright William. E. Howden 15
Image of page 15

Subscribe to view the full document.

Component Decomposition Divide the program up into separate  pieces Goals “divide and conquer”  “intellectual manageablity”  facilitate change and reuse What are the characteristics of a good  decomposition?
Image of page 16
Image of page 17
You've reached the end of this preview.
  • Fall '07
  • Howden
  • William. E. Howden, Copyright William. E.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern