1 / 66

1 Software Engineering Principles

1 Software Engineering Principles. Programming Life Cycle Activities. Problem analysis understand the problem Requirements definition specify what program will do High- and low-level design how it meets requirements Implementation of design code it

morrie
Télécharger la présentation

1 Software Engineering Principles

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. 1Software Engineering Principles

  2. Programming Life Cycle Activities • Problem analysis understand the problem • Requirements definition specify what program will do • High- and low-level design how it meets requirements • Implementation of design code it • Testing and verification detect errors, show correct • Delivery turn over to customer • Operation use the program • Maintenance change the program

  3. Software Engineering • A disciplined approach to the design, production, and maintenance of computer programs • that are developed on time and within cost estimates, • using tools that help to manage the size and complexity of the resulting software products.

  4. An Algorithm Is . . . • A logical sequence of discrete steps ( a step by step description) that describes a complete solution to a given problem computable in a finite amount of time.

  5. Toolboxes • Hardware – computers and their peripheral devices • Software – OS, text editors, debugging programs, test data generators etc. • Ideaware – knowledge collected over time: algorithms to solve common problems, as well as data structures; programming methodologies: top-down and object-oriented design; tools for measuring, evaluating, and proving the correctness of our programs.

  6. Goals of Quality Software • 1. It works. It should meet the user’s requirements. • 2. It can be modified. Software changes can happen in all phases of its life cycle. • What makes a program easy to modify? It should be readable and understable. • 3. It is reusable. • A well-designed, clearly written, well-documented program. It’s difficult to remember all the details after some time passed. So it can be quickly determines whether it can be reused for a new project. • Try to generalize routines. • 4. It is completed on time and within budget. Failure to meet deadlines is expensive.

  7. 1. Program Specification – translates the user’s requirements • Tells what the program must do, but not how it does it. • It is written documentation about the program.

  8. 1. Software Specification – a detailed description - includes • Inputs (do you need to check for errors in the input) • Outputs • Processing requirements and error handling • Assumptions about the problem

  9. 1. Software Specification – a detailed description • Can include User/operational/scenario • A scenario is a sequence of events for one execution of the program p.8 see an ATM example • Scenarios allow us to get a feel for the behavior expected from the system. A single scenario cannot show all possible behaviors. • Can serve as an important piece written documentation • Clarifies the problem to be solved

  10. Fundamental Principles of Software Engineeringused in the Program Design • 1. Abstraction • A model of a complex system that includes only the details essential to the perspective of the viewer of the system. e.g. although the earth in oblate ellipsoid, globes (models of the earth) are spheres e.g. the car user versus the automotive brake engineer Abstraction is our most powerful tool for dealing with this complexity.

  11. Fundamental Principles of Software Engineering • 2. Information Hiding • Hiding the details of a function or data structure with the goal of controlling access to the details of a module or structure. PURPOSE: To prevent high-level designs from dependingon low-level design details that may be changed. Lower levels of the program design are hidden from the higher levels. Changes in lower levels shouldn’t result in changes in higher levels. The programmers seesonly the details that are relevant at a particular level of the design (e.g. you can stop a car without knowing whether it has disk or drum brakes). You don’t want to require a complete understanding of the complicated details for the design of higher-level routines (complexity decrease).

  12. Fundamental Principles of Software Engineering • 3. Stepwise Refinement • A problem is approached in stages. Similar steps are followed during each stage, with the only difference being the level of detail involved. Some strategies: • Top-down – the problem is first broken into several large parts. Each of these parts is, in turn, divided into sections, the sections are subdived, and so on. • Bottom-up – the details comes first. After the detailed components are identified and designed, they are brought together into increasingly higher level components. • Functional decomposition – is top-down stepwise refinement with an emphasis on functions. • Round-trip gestalt design – is top-down stepwise refinement to object-oriented design; identify objects and their relationships, do many round of design.

  13. CRC • Visual Aids – CRC (Class, Responsibility and Collaboration ) Cards • tool for refining an object-oriented design. • identify and assign • responsibilities (verbs implemented by functions and • collaborations (other classes or objects that are used in fulfilling the responsibility.

  14. Visual Aids – CRC

  15. Identifies various objects composed of data and operations, that can be used together to solve the problem. Divides theproblem intomore easily handled subtasks,until the functional modules (subproblems) can be coded. Two Approaches to Building Manageable Modules FUNCTIONALDECOMPOSITION = top-down design OBJECT-ORIENTED DESIGN FOCUS ON: tasks (processes)FOCUS ON: data objects In both design methodologies, abstraction and information hiding are of primary importance.

  16. Find Weighted Average Print Weighted Average Functional Design Main Get Data Prepare File for Reading Print Data Print Heading

  17. Functional Design • In functional decomposition • the main module of the design becomes the main program and subsections develop into functions • information hiding is accomplished primarily through deferring the details of algorithms • Mix Strategy – combination of top-down design and OO design • When decomposition reaches the level of operation on data, you can implement the data and operations as objects

  18. Object-Oriented Design A technique for developing a program in which the solution is expressed in terms of objects-- self- contained entities composed of data and operations on that data. cin cout << >> setf get Private data Private data . . . . . . ignore

  19. More about OOD • Languages supporting OOD include: C++, Java, Smalltalk, Eiffel, and Object-Pascal. • Aclass is a programmer-defined data type and objects are variables of that type. • In C++, • cin is an object of a data type (class) named istream, and • coutis an object of a class ostream. • Header files iostream and fstream contain definitions of stream classes. • C++ types are templates for variables; classes are templates for objects

  20. Procedural vs. Object-Oriented Code “Read the specification of the software you want to build. Underline the verbs if you are after procedural code, the nouns if you aim for an object-oriented program.” Grady Booch, “What is and Isn’t Object Oriented Design,” 1989. Functional decomposition produces a hierarchy of tasks Object-oriented design produces a hierarchy of cooperating objects

  21. DATA SET 1 DATA SET 2 DATA SET 3 Program Testing • Testing is the process of executing a program with various data sets designed to discover errors. DATA SET 4 . . .

  22. For Each Test Case: • Determine inputs. • Determine the expected behavior of the program. • Run the program and observe the resulting behavior. • Compare the expected behavior and the actual behavior.

  23. Program Verification • Program Verification is the process of determining the degree to which a software product fulfills itsspecifications. SPECIFICATIONS Inputs Outputs Processing Requirements Assumptions PROGRAM

  24. Program Validation • The process of determining the degree to which software fulfills its intendedpurpose.

  25. Verification vs. Validation Program verification asks, “Are we doing the job right?” Program validation asks, “Are we doing the right job?” B. W. Boehm, Software Engineering Economics, 1981.

  26. Types of Errors • Specification • Design • Coding • Input

  27. Cost of a Specification Error Based on When It Is Discovered

  28. BASIC PRINCIPLE • A basic principle about software costs: • The earlier in the development cycle a problem is detected, the cheaper it is to fix.

  29. EXPERT KNOWLEDGE • It is worthwhile to develop an expert knowledge of both • The control and data structures • The syntax of the language

  30. cin (of type istream) cout (of type ostream) Keyboard and Screen I/O #include <iostream> using namespace std; output data input data executing program Keyboard Screen

  31. namespace • In slides that follow, assume the statement: using namespace std; • We explain namespace in Chapter 2

  32. <iostream> is header file • for a library that defines 3 objects • an istream object named cin (keyboard) • an ostream object named cout (screen) • an ostream object named cerr(screen)

  33. Insertion Operator ( << ) • The insertion operator << takes 2 operands. cout << “Enter part number followed by return : “ ; • The left operand is a stream expression, such as cout. • The right operand is an expression describing what to insert into the output stream.It may be of simple type, or a string, or a manipulator (like endl).

  34. Extraction Operator ( >> ) • Variable cin is predefined to denote an input stream from the standard input device( the keyboard ). cin >> partNumber ; • The extraction operator >> called “get from” takes 2 operands. The left operand is a stream expression, such as cin. The right operand is a variable of simple type. • Operator >> attempts to extract the next item from the input stream and store its value in the right operand variable.

  35. Extraction Operator >> “skips”(reads but does not store anywhere) leading whitespace characters (blank, tab, line feed, form feed, carriage return) before extracting the input value from the stream (keyboard or file). To avoid skipping, use function get to read the next character in the input stream. cin.get(inputChar);

  36. #include <iostream> using namespace std; int main( ) { // USES KEYBOARD AND SCREEN I/O int partNumber; float unitPrice; cout << “Enter part number followed by return : “ << endl ; // prompt cin >> partNumber ; cout << “Enter unit price followed by return : “ << endl ; cin >> unitPrice ; cout << “Part # “ << partNumber // echo << “at Unit Cost: $ “ << unitPrice << endl ; return 0; } 36

  37. input data output data Disk files for I/O #include <fstream> disk file “A:\myInfile.dat” disk file “A:\myOut.dat” executing program your variable (of type ifstream) your variable (of type ofstream)

  38. For File I/O • 1. use #include <fstream> • 2. choose valid variable identifiers for your files and declare them ifstream myInfile; // declarations ofstream myOutfile; • 3. open the files and associate them with disk names myInfile.open(“A:\\myIn.dat”);// open files myOutfile.open(“A:\\myOut.dat”); • 4. use your variable identifiers with >> and << • 5. close the files myInfile.close( ); // close files myOutfile.close( );

  39. Statements for using file I/O #include <fstream> using namespace std; ifstream myInfile; // declarations ofstream myOutfile; myInfile.open(“A:\\myIn.dat”);// open files myOutfile.open(“A:\\myOut.dat”); myInfile.close( ); // close files myOutfile.close( );

  40. What does opening a file do? • associates the C++ identifier for your file with the physical (disk) name for the file • if the input file does not exist on disk, open is not successful • if the output file does not exist on disk, a new file with that name is created • if the output file already exists, it is erased • places a file reading marker at the very beginning of the file, pointing to the first character in it

  41. #include <fstream> using namespace std; int main( ) { // USES FILE I/O int partNumber; float unitPrice; ifstream inFile; // declare file variables ofstream outFile; inFile.open(“input.dat”); //open files outFile.open(“output.dat”); inFile >> partNumber ; inFile >> unitPrice ; outFile << “Part # “ << partNumber // echo << “at Unit Cost: $ “ << unitPrice << endl ; return 0; } 41

  42. Stream Failure • When a stream enters the fail state, further I/O operations using that stream are ignored. But the computer does not automatically halt the program or give any error message. !!! • Possible reasons for entering fail state include: • invalid input data (often the wrong type), • trying to input a value when the stream is at the end of the file, • opening an input file that doesn’t exist, • opening an output file on a diskette that is already full or is write-protected.

  43. #include <fstream> #include <iostream> using namespace std; int main( ) { // CHECKS FOR STREAM FAIL STATE ifstream inFile; inFile.open(“input.dat”); // try to open file if ( !inFile ) //test the state of the stream { cout << “File input.dat could not be opened.”; return 1; } . . . return 0; //the ISO Standard – a successful completion code } 43

  44. Various Types of Errors • Design errors occur when specifications are wrong • Compile errors occur when syntax is wrong • Run-time errors result from • incorrect assumptions, • incomplete understanding of the programming language, or • unanticipated user errors.

  45. Robustness • Robustness is the ability of a program to recover following an error; the ability of a program to continue to operate within its environment. • It is generally unwise to make too many assumptions about the correctness of input • check explicitly for the correct type and bounds of such input • Decide how an error should be handle • request new input, • print a message, or • go on to the next data • Some run-time errors • Swapped 2 parameters of the same type on a function call, • Forgotten to designate a function’s output data as a reference parameter

  46. An Assertion • Is a logical proposition that is either true or false (not necessarily in C++ code). EXAMPLES studentCount is greater than 0 sum is assigned && count > 0 response has value ‘y’ or ‘n’ partNumber == 5467 We use preconditions and postconditions at the module level or function level because it help us to design programs in a truly modular fashion.

  47. Preconditions and Postconditions • The preconditionis an assertion describing what a function requires to be truebefore beginning execution. • The postconditiondescribes what must be true at the moment the function finishes execution. • The calleris responsible for ensuring the precondition, and the function code must ensure the postcondition. FOR EXAMPLE . . .

  48. void PrintList ( ofstream& dataFile, UnsortedType list) // Pre: list has been initialized. // dataFile is open for writing. // Post: Each component in list has been written to dataFile. // dataFile is still open. { using namespace std; int length; ItemType item; list.ResetList(); length = list.LengthIs(); for (int counter = 1; counter <= length; counter++) { list.GetNextItem(item); item.Print(dataFile); } } 48

  49. Another Example void Getroots (float a, float b, float c, float& root1, float& root2 ) // Pre: a, b, and c are assigned. // a is non-zero, b*b - 4*a*c is non-negative. // Post: root1 and root2 are assigned // root1 and root2 are roots of quadratic with coefficients a, b, c { using namespace std; float temp; temp = b * b - 4.0 * a * c; root1 = (-b + sqrt(temp) ) / ( 2.0 * a ); root2 = (-b - sqrt(temp) ) / ( 2.0 * a ); return; }

  50. Design Review • 1. Deskchecking is tracing an execution of a design or program on paper (see p. 32) • A checklist of typical errors: • Verify essential data (variables, input values, parameters of subprograms) • Loops that don’t terminate, • Variables that are used before they are initialized, • Incorrect order of parameters on function calls

More Related