1 / 33

Chapter 1 The Phases of Software Development

Learn about the different phases of software development, including specification, design, implementation, analysis, testing, maintenance, and obsolescence. Understand the importance of preconditions and postconditions in ensuring the validity of functions.

rustyl
Download Presentation

Chapter 1 The Phases of Software Development

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. Chapter 1 The Phases of Software Development

  2. Software Development Phases • Specification of the task • Design of a solution • Implementation of solution • Analysis of solution • Testing and debugging • Maintenance and evolution of the system • Obsolescence

  3. Specification • Precise description of problem • May be one of the most difficult phases

  4. Design • Algorithm – set of instructions for solving problem • Not originally done in programming language • pseudocode • Formal modeling language (UML) • Decompose problem into smaller – more manageable subtasks – map to subprograms • Need to be as independent of each other as possible • Reuse • Modification • All domain information should be located only 1 place in the code • Each subprogram should only do 1 task • Each subprogram should be treated as a black box – specification not implementation – called procedural abstraction / information hiding

  5. Preconditions and Postconditions • An important topic: preconditions and postconditions. • They are a method of specifying what a function accomplishes. Data Structures and Other Objects Using C++

  6. Preconditions and Postconditions Frequently a programmer must communicate precisely whata function accomplishes, without any indication of how the function does its work. Can you think of a situation where this would occur ?

  7. Example HERE ARE THE REQUIREMENTS FOR A FUNCTION THAT I WANT YOU TO WRITE. • You are the head of a programming team and you want one of your programmers to write a function for part of a project. I DON'T CARE WHAT METHOD THE FUNCTION USES, AS LONG AS THESE REQUIREMENTS ARE MET.

  8. What are Preconditions and Postconditions? • One way to specify such requirements is with a pair of statements about the function. • The precondition statement indicates what must be true before the function is called. • The postcondition statement indicates what will be true when the function finishes its work.

  9. Example void write_sqrt(double x) // Precondition: x >= 0. // Postcondition: The square root of x has // been written to the standard output. ...

  10. Example • The precondition and postcondition appear as comments in your program. void write_sqrt( double x) // Precondition: x >= 0. // Postcondition: The square root of x has // been written to the standard output. ... }

  11. Example • In this example, the precondition requires that x >= 0 be true whenever the function is called. void write_sqrt( double x) // Precondition: x >= 0. // Postcondition: The square root of x has // been written to the standard output. ... }

  12. write_sqrt( -10 ); write_sqrt( 0 ); write_sqrt( 5.6 ); Example Which of these function calls meet the precondition ?

  13. write_sqrt( -10 ); write_sqrt( 0 ); write_sqrt( 5.6 ); Example Which of these function calls meet the precondition ? The second and third calls are fine, since the argument is greater than or equal to zero.

  14. write_sqrt( -10 ); write_sqrt( 0 ); write_sqrt( 5.6 ); Example Which of these function calls meet the precondition ? But the first call violates the precondition, since the argument is less than zero.

  15. Example • The postcondition always indicates what work the function has accomplished. In this case, when the function returns the square root of xhas been written. void write_sqrt( double x) // Precondition: x >= 0. // Postcondition: The square root of x has // been written to the standard output. ... }

  16. Another Example bool is_vowel( char letter ) // Precondition: letter is an uppercase or // lowercase letter (in the range 'A' ... 'Z' or 'a' ... 'z') . // Postcondition: The value returned by the // function is true if Letter is a vowel; // otherwise the value returned by the function is // false. ...

  17. Another Example What values will be returned by these function calls ? is_vowel( 'A' ); is_vowel(' Z' ); is_vowel( '?' );

  18. Another Example What values will be returned by these function calls ? true is_vowel( 'A' ); is_vowel(' Z' ); is_vowel( '?' ); false Nobody knows, because the precondition has been violated.

  19. Another Example What values will be returned by these function calls ? is_vowel( '?' ); Violating the precondition might even crash the computer.

  20. AT THIS POINT, MY PROGRAM CALLS YOUR FUNCTION, AND I MAKE SURE THAT THE PRECONDITION IS VALID. Always make sure the precondition is valid . . . • The programmer who calls the function is responsible for ensuring that the precondition is valid when the function is called.

  21. THEN MY FUNCTION WILL EXECUTE, AND WHEN IT IS DONE, THE POSTCONDITION WILL BE TRUE. I GUARANTEE IT. . . . so the postcondition becomes true at the function’s end. • The programmer who writes the function counts on the precondition being valid, and ensures that the postcondition becomes true at the function’s end.

  22. You The programmer who wrote that torrential function Noah A Quiz Suppose that you call a function, and you neglect to make sure that the precondition is valid. Who is responsible if this inadvertently causes a 40-day flood or other disaster?

  23. You The programmer who calls a function is responsible for ensuring that the precondition is valid. A Quiz Suppose that you call a function, and you neglect to make sure that the precondition is valid. Who is responsible if this inadvertently causes a 40-day flood or other disaster?

  24. On the other hand, careful programmers also follow these rules: • When you write a function, you should make every effort to detect when a precondition has been violated. • If you detect that a precondition has been violated, then print an error message and halt the program.

  25. On the other hand, careful programmers also follow these rules: • When you write a function, you should make every effort to detect when a precondition has been violated. • If you detect that a precondition has been violated, then print an error message and halt the program... • ...rather than causing a disaster.

  26. Example • The assert function (described in Section 1.1) is useful for detecting violations of a precondition. void write_sqrt( double x) // Precondition: x >= 0. // Postcondition: The square root of x has // been written to the standard output. { assert(x >= 0); ...

  27. Advantages of Using Preconditions and Postconditions • Succinctly describes the behavior of a function... • ... without cluttering up your thinking with details of how the function works. • At a later point, you may reimplement the function in a new way ... • ... but programs (which only depend on the precondition/postcondition) will still work with no changes.

  28. Summary Postcondition • The programmer who writes a function ensures that the postcondition is true when the function finishes executing. Precondition • The programmer who calls a function ensures that the precondition is valid. • The programmer who writes a function can bank on the precondition being true when the function begins execution.

  29. C++ Features: Standard Library & Standard Namespace #include directive Similar to import directive in other languages Much more primitive Namespaces – allows limiting visibility of “names” Standard namespace – standard C++ libraries 2 choices using namespace std: Fully qualified identifier

  30. Exception Handling Similar to Java and C#

  31. Running Time Analysis Machine independent method of measuring run time efficiency Determine basic operation for the algorithm Expression the number of operations as a function of the data size Interested in the order of magnitude of this function – expressed using Big-O notation

  32. Running Time Analysis Worst case – maximum number of operations Best case – minimum number of operations Average case – depends upon the underlying probability distribution

  33. Testing and Debugging Good test data Correct output known Include values most likely to causes errors Boundary values Fully exercise code Every line of code is executed by at least 1 test case

More Related