Presentation is loading. Please wait.

Presentation is loading. Please wait.

Software Development p Data structure p A collection of data organized so that the data can be accessed using a set of specific techniques p Object-oriented.

Similar presentations


Presentation on theme: "Software Development p Data structure p A collection of data organized so that the data can be accessed using a set of specific techniques p Object-oriented."— Presentation transcript:

1 Software Development p Data structure p A collection of data organized so that the data can be accessed using a set of specific techniques p Object-oriented programming p A method of programming that emphasizes information hiding and component reuse

2 Phases of Software Development p Specification of the task p Design a solution p Implementation of the solution p Analysis of the solution p Testing/debugging the implementation p Maintenance and evolution of the system

3 Specifications p Requirements define the scope of the project p Resources specifies people, equipment, software, time, and money available p Specifications describe precisely what the software should do

4 Design p Describes how the software meets the specifications p Typically describes components of the software and how they interact

5 Implementation p Translating the design into a specified programming language(s) p Must follow style guidelines p Don’t change the design without going to a previous phase

6 Analysis p How well does the implementation meet the specifications p Sometimes referred to as validation

7 Testing and Debugging p Goal is to find bugs before user does p Alpha versus beta testing p Regression testing p Integration testing p Top-down versus bottom-up p Must consider p Boundary cases p Exceptional cases p Expected error cases

8 Lubarsky’s Law of Cybernetic Entomology There’s always one more bug!

9 Brook’s Law Adding more programmers to a late software project makes it later

10 Deadline-Dan’s Demon Every task takes twice as long as you think it will. If you double the time you think it will take, it will take 4 times as long.

11 Gilb’s 2 nd Law of Unreliability Any system that depends on human reliability is inherently unreliable.

12 p An important topic: preconditions and postconditions. p They are a method of specifying what a method accomplishes. Preconditions and Postconditions Data Structures and Other Objects Using Java

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

14 Example p You are the head of a programming team and you want one of your programmers to write a method for part of a project. HERE ARE THE REQUIREMENTS FOR A METHOD THAT I WANT YOU TO WRITE. I DON'T CARE HOW THE METHOD WORKS, AS LONG AS THESE REQUIREMENTS ARE MET.

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

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

17 Example // Precondition: x >= 0. // Postcondition: The square root of x has // been written to the standard output. public void writeSqrt( double x)... } p The precondition and postcondition appear as comments in your program. p They are usually placed before the method’s implementation.

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

19 Example writeSqrt( -10 ); writeSqrt( 0 ); writeSqrt( 5.6 ); Which of these method calls meet the precondition ?

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

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

22 Example // Precondition: x >= 0. // Postcondition: The square root of x has // been written to the standard output. public void writeSqrt( double x)... }  The postcondition always indicates what work the method has accomplished. In this case, when the method returns the square root of x has been written.

23 Another Example // Precondition: letter is an uppercase or // lowercase letter (in the range 'A'... 'Z' or 'a'... 'z'). // Postcondition: The value returned by the // method is true if letter is a vowel; // otherwise the value returned by the method is // false. public boolean isVowel( char letter )...

24 Another Example isVowel( 'A' ); isVowel(' Z' ); isVowel( '?' ); What values will be returned by these method calls ?

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

26 Another Example isVowel( '?' ); What values will be returned by these method calls ? Violating the precondition might even crash the program.

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

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

29 A Quiz Suppose that you call a method, 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? ¬You ­The programmer who wrote that torrential method ®Noah

30 A Quiz Suppose that you call a method, 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? ¬You The programmer who calls a method is responsible for ensuring that the precondition is valid. The programmer who calls a method is responsible for ensuring that the precondition is valid.

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

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

33 Example // Precondition: x >= 0. // Postcondition: The square root of x has // been written to the standard output. public void writeSqrt( double x) { if (x < 0) throw new IllegalArgumentException(“Negative x”);... p Throwing an exception(described in Section 1.1) is useful.

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

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

36 T HE E ND Presentation copyright 1999, Addison Wesley Longman For use with Data Structures and Other Objects Using Java by Michael Main. Some artwork in the presentation is used with permission from Presentation Task Force (copyright New Vision Technologies Inc.) and Corel Gallery Clipart Catalog (copyright Corel Corporation, 3G Graphics Inc., Archive Arts, Cartesia Software, Image Club Graphics Inc., One Mile Up Inc., TechPool Studios, Totem Graphics Inc.). Students and instructors who use Data Structures and Other Objects Using Java are welcome to use this presentation however they see fit, so long as this copyright notice remains intact.


Download ppt "Software Development p Data structure p A collection of data organized so that the data can be accessed using a set of specific techniques p Object-oriented."

Similar presentations


Ads by Google