software development p data structure p a collection of data organized so that the data can be...

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

Upload: rachel-adams

Post on 05-Jan-2016

215 views

Category:

Documents


2 download

TRANSCRIPT

Page 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

Software DevelopmentSoftware Development

Data structureData structure A collection of data organized so that the data A collection of data organized so that the data

can be accessed using a set of specific can be accessed using a set of specific techniquestechniques

Object-oriented programmingObject-oriented programming A method of programming that emphasizes A method of programming that emphasizes

information hiding and component reuseinformation hiding and component reuse

Page 2: 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

Phases of Software DevelopmentPhases of Software Development

Specification of the taskSpecification of the task Design a solutionDesign a solution Implementation of the solutionImplementation of the solution Analysis of the solutionAnalysis of the solution Testing/debugging the implementationTesting/debugging the implementation Maintenance and evolution of the systemMaintenance and evolution of the system

Page 3: 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

Specifications Specifications

RequirementsRequirements define the scope of the define the scope of the projectproject

ResourcesResources specifies people, equipment, specifies people, equipment, software, time, and money availablesoftware, time, and money available

SpecificationsSpecifications describe precisely describe precisely whatwhat the the software should dosoftware should do

Page 4: 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

Design Design

Describes Describes howhow the software meets the the software meets the specificationsspecifications

Typically describes components of the Typically describes components of the software and how they interactsoftware and how they interact

Page 5: 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

Implementation Implementation

Translating the design into a specified Translating the design into a specified programming language(s)programming language(s)

Must follow style guidelinesMust follow style guidelines Don’t change the design without going to a Don’t change the design without going to a

previous phaseprevious phase

Page 6: 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

Analysis Analysis

How well does the implementation meet the How well does the implementation meet the specificationsspecifications

Sometimes referred to as Sometimes referred to as validationvalidation

Page 7: 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

Testing and DebuggingTesting and Debugging

Goal is to find bugs before user doesGoal is to find bugs before user does Alpha versus beta testingAlpha versus beta testing Regression testingRegression testing Integration testingIntegration testing Top-down versus bottom-upTop-down versus bottom-up Must considerMust consider

Boundary casesBoundary cases Exceptional casesExceptional cases Expected error casesExpected error cases

Page 8: 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

Lubarsky’s Law of Cybernetic Entomology

Lubarsky’s Law of Cybernetic Entomology

There’s always one more bug!There’s always one more bug!

Page 9: 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

Brook’s LawBrook’s Law

Adding more programmers to a late software Adding more programmers to a late software project makes it laterproject makes it later

Page 10: 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

Deadline-Dan’s DemonDeadline-Dan’s Demon

Every task takes twice as long as you think it Every task takes twice as long as you think it will. If you double the time you think it will. If you double the time you think it

will take, it will take 4 times as long.will take, it will take 4 times as long.

Page 11: 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

Gilb’s 2nd Law of UnreliabilityGilb’s 2nd Law of Unreliability

Any system that depends on human reliability Any system that depends on human reliability is inherently unreliable.is inherently unreliable.

Page 12: 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

An important topic: An important topic: preconditionspreconditions and and postconditionspostconditions..

They are a method of They are a method of specifying what a specifying what a method accomplishes.method accomplishes.

Preconditions and PostconditionsPreconditions and Postconditions

Data StructuresData Structuresand Other Objectsand Other ObjectsUsing JavaUsing Java

Page 13: 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

Preconditions and PostconditionsPreconditions and Postconditions

Frequently a programmer must communicate Frequently a programmer must communicate precisely precisely whatwhat a method accomplishes, a method accomplishes, without any indication of without any indication of howhow the method the method does its work.does its work.

Can you think of a situationCan you think of a situationwhere this would occur ?where this would occur ?

Page 14: 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

ExampleExample

You are the head of a You are the head of a programming team programming team and you want one of and you want one of your programmers to your programmers to write a method forwrite a method for part of a project.part of a project.

HERE ARETHE REQUIREMENTS

FOR A METHOD THAT IWANT YOU TO

WRITE.

I DON'T CAREHOW THE

METHOD WORKS,AS LONG AS THESE

REQUIREMENTSARE MET.

Page 15: 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

What are Preconditions and Postconditions?What are Preconditions and Postconditions?

One way to specify such requirements is One way to specify such requirements is with a pair of statements about the method.with a pair of statements about the method.

The The preconditionprecondition statement indicates what statement indicates what must be true before the method is called.must be true before the method is called.

The The postconditionpostcondition statement indicates what statement indicates what will be true when the method finishes its will be true when the method finishes its work.work.

Page 16: 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

ExampleExample

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

...

Page 17: 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

ExampleExample

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

...}

The precondition and postcondition The precondition and postcondition appear as comments in your appear as comments in your program.program.

They are usually placed before the They are usually placed before the method’s implementation.method’s implementation.

Page 18: 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

ExampleExample

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

...}

In this example, the precondition In this example, the precondition requires thatrequires that

x >= 0x >= 0

be true whenever the method is called.be true whenever the method is called.

Page 19: 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

ExampleExample

writeSqrt( -10 );writeSqrt( 0 );writeSqrt( 5.6 );

Which of these method callsWhich of these method callsmeet the precondition ?meet the precondition ?

Page 20: 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

ExampleExample

Which of these method callsWhich of these method callsmeet the precondition ?meet the precondition ?

The second and third calls are fine, sinceThe second and third calls are fine, sincethe argument is greater than or equal to zero.the argument is greater than or equal to zero.

writeSqrt( -10 );writeSqrt( 0 );writeSqrt( 5.6 );

Page 21: 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

ExampleExample

Which of these method callsWhich of these method callsmeet the precondition ?meet the precondition ?

But the first call violates the precondition,But the first call violates the precondition,since the argument is less than zero.since the argument is less than zero.

writeSqrt( -10 );writeSqrt( 0 );writeSqrt( 5.6 );

Page 22: 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

ExampleExample

// 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 The postcondition always indicates what work the method has what work the method has accomplished. In this case, when the accomplished. In this case, when the method returns the square root of method returns the square root of xx has been written. has been written.

Page 23: 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

Another ExampleAnother 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 )

...

Page 24: 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

Another ExampleAnother Example

isVowel( 'A' );isVowel(' Z' );isVowel( '?' );

What values will be returnedWhat values will be returnedby these method calls ?by these method calls ?

Page 25: 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

Another ExampleAnother Example

isVowel( 'A' );isVowel(' Z' );isVowel( '?' );

What values will be returnedWhat values will be returnedby these method calls ?by these method calls ? truetrue

falsefalse

Nobody knows, because theNobody knows, because theprecondition has been violated.precondition has been violated.

Page 26: 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

Another ExampleAnother Example

isVowel( '?' );

What values will be returnedWhat values will be returnedby these method calls ?by these method calls ?

Violating the preconditionViolating the preconditionmight even crash the program.might even crash the program.

Page 27: 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

Always make sure the precondition is valid . . .Always make sure the precondition is valid . . .

The programmer who The programmer who calls the method is calls the method is responsible for responsible for ensuring that the ensuring that the precondition is valid precondition is valid when the method is when the method is called.called.

AT THIS POINT, MYPROGRAM CALLS YOUR

METHOD, AND I MAKESURE THAT THE

PRECONDITION ISVALID.

Page 28: 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

. . . so the postcondition becomes true at the method’s end. . . . so the postcondition becomes true at the method’s end.

The programmer who The programmer who writes the method counts writes the method counts on the precondition being on the precondition being valid, and valid, and ensures that the ensures that the postcondition becomes postcondition becomes true true at the method’s end.at the method’s end.

THEN MY METHODWILL EXECUTE, AND WHEN

IT IS DONE, THEPOSTCONDITION WILL BE

TRUE.I GUARANTEE IT.

Page 29: 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

A QuizA Quiz

Suppose that you call Suppose that you call a method, and you a method, and you neglect to make sure neglect to make sure that the precondition that the precondition is valid. is valid. Who is responsible if Who is responsible if this inadvertently this inadvertently causes a 40-day flood causes a 40-day flood or other disaster?or other disaster?

YouYouThe programmer who The programmer who

wrote that torrential wrote that torrential methodmethod

NoahNoah

Page 30: 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

A QuizA Quiz

Suppose that you call Suppose that you call a method, and you a method, and you neglect to make sure neglect to make sure that the precondition that the precondition is valid. is valid. Who is responsible if Who is responsible if this inadvertently this inadvertently causes a 40-day flood causes a 40-day flood or other disaster?or other disaster?

YouYou

The programmer who The programmer who calls a method is calls a method is responsible for responsible for ensuring that the ensuring that the precondition is valid.precondition is valid.

Page 31: 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

On the other hand, careful programmers also follow these rules:On the other hand, careful programmers also follow these rules:

When you write a method, you should make When you write a method, you should make every effort to detect when a precondition every effort to detect when a precondition has been violated.has been violated.

If you detect that a precondition has been If you detect that a precondition has been violated, then print an error message and violated, then print an error message and halt the program.halt the program.

Page 32: 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

On the other hand, careful programmers also follow these rules:On the other hand, careful programmers also follow these rules:

When you write a method, you should make When you write a method, you should make every effort to detect when a precondition every effort to detect when a precondition has been violated.has been violated.

If you detect that a precondition has been If you detect that a precondition has been violated, then print an error message and halt violated, then print an error message and halt the program...the program...

...rather than causing...rather than causing

a disaster.a disaster.

Page 33: 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

ExampleExample

// 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”);

... Throwing an Throwing an exception(described in exception(described in Section 1.1) is useful.Section 1.1) is useful.

Page 34: 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

Advantages of Using Preconditions and PostconditionsAdvantages of Using Preconditions and Postconditions

Succinctly describes the behavior of a method...Succinctly describes the behavior of a method... ... without cluttering up your thinking with ... without cluttering up your thinking with

details of how the method works.details of how the method works. At a later point, you may reimplement the At a later point, you may reimplement the

method in a new way ...method in a new way ... ... but programs (which only depend on the ... but programs (which only depend on the

precondition/postcondition) will still work with precondition/postcondition) will still work with no changes.no changes.

Page 35: 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

PreconditionPrecondition The programmer who calls The programmer who calls

a method ensures that the a method ensures that the precondition is valid.precondition is valid.

The programmer who The programmer who writes a method can bank writes a method can bank on the precondition being on the precondition being true when the method true when the method begins execution.begins execution.

PostconditionPostcondition The programmer The programmer

who writes a who writes a method ensures method ensures that the that the postcondition is postcondition is true when the true when the method finishes method finishes executing.executing.

SummarySummary

Page 36: 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

THE ENDTHE END

Presentation copyright 1999, Addison Wesley LongmanPresentation copyright 1999, Addison Wesley LongmanFor use with For use with Data Structures and Other Objects Using JavaData Structures and Other Objects Using Javaby Michael Main.by Michael Main.

Some artwork in the presentation is used with permission from Presentation Task ForceSome artwork in the presentation is used with permission from Presentation Task Force(copyright New Vision Technologies Inc.) and Corel Gallery Clipart Catalog (copyright(copyright New Vision Technologies Inc.) and Corel Gallery Clipart Catalog (copyrightCorel Corporation, 3G Graphics Inc., Archive Arts, Cartesia Software, Image ClubCorel Corporation, 3G Graphics Inc., Archive Arts, Cartesia Software, Image ClubGraphics Inc., One Mile Up Inc., TechPool Studios, Totem Graphics Inc.).Graphics Inc., One Mile Up Inc., TechPool Studios, Totem Graphics Inc.).

Students and instructors who use Students and instructors who use Data Structures and Other ObjectsData Structures and Other Objects Using Java Using Java arearewelcome to use this presentation however they see fit, so long as this copyright notice welcome to use this presentation however they see fit, so long as this copyright notice remains intact.remains intact.