1 software engineering principles
This presentation is the property of its rightful owner.
Sponsored Links
1 / 66

1 Software Engineering Principles PowerPoint PPT Presentation


  • 64 Views
  • Uploaded on
  • Presentation posted in: General

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

Download Presentation

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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


1 software engineering principles

1Software Engineering Principles


Programming life cycle activities

Programming Life Cycle Activities

  • Problem analysisunderstand the problem

  • Requirements definition specify what program will do

  • High- and low-level designhow it meets requirements

  • Implementation of designcode it

  • Testing and verificationdetect errors, show correct

  • Deliveryturn over to customer

  • Operationuse the program

  • Maintenancechange the program


Software engineering

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.


An algorithm is

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.


Toolboxes

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.


Goals of quality software

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.


1 program specification translates the user s requirements

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.


1 software specification a detailed description includes

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


1 software specification a detailed description

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


Fundamental principles of software engineering used in the program design

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.


Fundamental principles of software engineering

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).


Fundamental principles of software engineering1

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.


1 software engineering principles

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.


Visual aids crc

Visual Aids – CRC


Two approaches to building manageable modules

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.


Functional design

Find

Weighted

Average

Print

Weighted

Average

Functional Design

Main

Get Data

Prepare

File for

Reading

Print Data

Print Heading


Functional design1

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


Object oriented design

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


More about ood

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


Procedural vs object oriented code

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


Program testing

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

. . .


For each test case

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.


1 software engineering principles

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


Program validation

Program Validation

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


Verification vs validation

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.


Types of errors

Types of Errors

  • Specification

  • Design

  • Coding

  • Input


Cost of a specification error based on when it is discovered

Cost of a Specification Error Based on When It Is Discovered


Basic principle

BASIC PRINCIPLE

  • A basic principle about software costs:

    • The earlier in the development cycle a problem is detected, the cheaper it is to fix.


Expert knowledge

EXPERT KNOWLEDGE

  • It is worthwhile to develop an expert knowledge of both

    • The control and data structures

    • The syntax of the language


Keyboard and screen i o

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


Namespace

namespace

  • In slides that follow, assume the statement:

    using namespace std;

  • We explain namespace in Chapter 2


Iostream is header file

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


Insertion operator

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).


Extraction operator

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.


Extraction operator1

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


1 software engineering principles

#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


Disk files for i o

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)


For file i o

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( );


Statements for using file i o

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( );


What does opening a file do

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


1 software engineering principles

#include <fstream>

using namespace std;

int main( )

{// USES FILE I/O

int partNumber;

float unitPrice;

ifstreaminFile;// declare file variables

ofstreamoutFile;

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


Stream failure

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.


1 software engineering principles

#include <fstream>

#include <iostream>

using namespace std;

int main( )

{// CHECKS FOR STREAM FAIL STATE

ifstreaminFile;

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


Various types of errors

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.


Robustness

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


An assertion

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.


Preconditions and postconditions

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 . . .


1 software engineering principles

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


Another example

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;

}


Design review

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


Design review1

Design Review

  • 2. Walk-Through is a verification method using a team to perform a manual simulation of the program or design, using sample test inputs, and keeping track of the program’s data by hand.

  • Its purpose is to stimulate discussion about the programmer’s design or implementation.

  • Successful completion of the design inspection means that testing of the program can begin


Design review2

Design Review

3. Inspection. A verification method in which one member of a team reads the program or design line by line and others point out errors.


Program testing1

Program Testing


Testing

Testing

Testing Selection Control Structures

  • to test a program with branches, use enough data sets so that every branch is executed at least once

  • this is called minimum complete coverage

    Unit testing. Testing a class or function by itself


Testing often combines two approaches

Testing Often Combines Two Approaches

WHITE BOX BLACK BOX

TESTING TESTING

Data Coverage

Data values at

the boundaries, and

possibly middle values,

example of each category of inputs can be tested.

Code Coverage

Allows us to see the

program code while

designing the tests.

Ensure that each statement in the program is executed at least once.

We could say that 75% of the branches of a program have been executed or 50% of the path have been tested (metric based testing).


Tasks within each test case

Tasks within each test case:

  • determine inputs that demonstrate the goal.

  • determine the expected behavior for the input.

  • run the program and observe results.

  • compare expected behavior and actual behavior. If they differ, we begin debugging.


How to test a program

How to Test a Program

  • design and implement a test plan

  • a test plan is a document that specifies the test cases planned for a program or module, which includes

    • purposes

    • conditions of the test cases

    • inputs,

    • and the expected output

  • implement the test plan by verifying that the program outputs the predicted results


Test plans

Test Plans

  • For program testing to be effective, it must be planned.

  • Start planning for testing before writing a single line of code.


Testing c data structures

Testing C++ Data Structures


1 software engineering principles

// Generic Test Driverfor the set of commands/operations p.47-48 implementation

Declare an instance of the class being tested

Prompt for, read the input file name, and open the file

Prompt for, read the output file name, and open the file

Prompt for and read the label (= test name) for the output file

Write the label on the output file

Read the next command from the input file

Set numCommands to 0

While the command read is not ‘quit’

Execute the command by invoking the member function of the same name

Print the results to the output file

Increment numCommands by 1

Print “Command number” numComands “completed” to the screen

Read the next command from the input file

Close the input and output files.

Print “Testing completed” to the screen


1 software engineering principles

// Test driver with instructions for filling in specific

// information

#include <iostream>

#include <fstream>

#include <string>

// #include file containing class to be tested

int main()

{

using namespace std;

ifstream inFile; // file containing operations

ofstream outFile; // file containing output

string inFileName; // input file external name

string outFileName; // output file external name

string outputLabel;

string command; // operation to be executed

int numCommands;

// Declare a variable of the type being tested

// Prompt for file names, read file names, and prepare files

cout << "Enter name of input file; press return." << endl;

cin >> inFileName;

inFile.open(inFileName.c_str());

cout << "Enter name of output file; press return." << endl;

cin >> outFileName;

outFile.open(outFileName.c_str());

cout << "Enter name of test run; press return." << endl;

cin >> outputLabel;

outFile << outputLabel << endl;

inFile >> command;

numCommands = 0;

while (command != "Quit")

{

// The following should be specific to structure being tested

// Execute the command by invoking the member function of the

// same name

// Print the results to the output file

numCommands++;

cout << "Command number " << numCommands << " completed."

<< endl:

inFile >> command;

}

cout << "Testing completed." << endl;

inFile.close();

outFile.close();

return 0;

}


Life cycle verification activities

Life-Cycle Verification Activities


Phase result testing technique

PHASE RESULT TESTING TECHNIQUE

Problem solving Algorithm Algorithm deskchecking,

walk-through

Implementation Coded program Code walk-through,

Trace

Compilation Object program Compiler messages

Execution Output Implement test plan


Integration testing

Integration Testing

  • Is performed to integrate program modules that have already been independently unit tested.

Main

Get Data

Print

Weighted

Average

Prepare

File for

Reading

Find

Weighted

Average

Print Data

Print Heading


Integration testing approaches

Integration Testing Approaches

TOP-DOWN

Assumption: the lower levels

work correctly

BOTTOM-UP

Ensures individual modules

work together correctly,

beginning with the

lowest level.

Ensures correct overall

design logic and the

interfaces between modules

are correct.

USES: placeholder USES: a test driver to call

module “stubs” to test the functions being tested.

the order of calls.

A stub may consist a single/Effective in a group programming

group trace/debug output statementsenvironment where each programmer has

tested already own modules/functions.


Summary

Summary

  • The earlier in the software development cycle program errors are detected, the easier and less costly in time, effort, and money the are to remove.


  • Login