undergraduate texts in computer science978-1-4684-9312-2/1.pdf · undergraduate texts in computer...

14
UNDERGRADUATE TEXTS IN COMPUTER SCIENCE Springer NewYork Berlin Heidelberg Barcelona Budapest HongKong London Milan Paris Santa Clara Singapore Tokyo Editors David Gries Fred B. Schneider

Upload: nguyentuyen

Post on 06-Apr-2018

218 views

Category:

Documents


2 download

TRANSCRIPT

UNDERGRADUATE TEXTS IN COMPUTER SCIENCE

Springer NewYork Berlin Heidelberg Barcelona Budapest HongKong London Milan Paris Santa Clara Singapore Tokyo

Editors David Gries

Fred B. Schneider

UNDERGRADUATE TEXTS IN COMPUTER SCIENCE

Beidler, Data Structures and Algorithms

Ja/ote, An Integrated Approach to Software Engineering, Second Edition

Kozen, Automata and Computability

Merritt and Stix, Migrating from Pascal to C++

Zeig/er, Objects and Systems

Pankaj Jalote

AN INTEGRATED APPROACH TO SOFTWARE

ENGINEERING Second Edition

With 108 Illustrations

" Springer

Pankaj Jalote Department of Computer Science

and Engineering Indian Institute of Technology Kanpur 208016 India

Series Editors David Gries Fred B. Schneider Department of Computer Science Comell University UpsonHall Ithaca, NY 14853-7501 USA

Library of Congress Cataloging-in-Publication Data Jalote, P.

An integrated approach to software engineering / Pankaj Jalote. -2nded.

p. cm. - (Undergraduate texts in computer science) IncIudes bibliographical references and index.

1. Software engineering I. Title. H. Series. QA76.758.J351997 005.1-dc20

Printed on acid-free paper.

96-38869

ISBN 978-1-4684-9314-6 ISBN 978-1-4684-9312-2 (eBook) DOI 10.1007/978-1-4684-9312-2

© 1997, 1991 Springer-Verlag New York, Inc.

Softcover reprint of the hardcover 2nd edition 1997

All rights reserved. This work may not be translated or copied in whole or in part without the written permission ofthe publisher (Springer-Verlag New York, Inc., 175 Fifth Avenue, New York, NY 10010, USA), except for brief excerpts in connection with reviews or scholarly analysis. Use in connection with any form of information storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now known or hereafter developed is forbidden. The use of general descriptive names, trade names, trademarks, etc., in this publication, even if the former are not especially identified, is not to be taken as a sign that such names, as understood by the Trade Marks and Merchandise Marks Act, may accordingly be used freely by anyone.

Production managed by Steven Pisano; manufacturing supervised by Johanna Tschebull. Camera-ready copy prepared from the author's Jb.TPC files.

98765432

Preface to the Second Edition

A lot has changed in the fast-moving area of software engineering since the first edition of this book came out. However, two particularly dominant trends are clearly discernible: focus on software processes and object-orientation. A lot more attention is now given to software processes because process improvement is con­sidered one of the basic mechanisms for improving quality and productivity. And the object-oriented approach is considered by many one of the best hopes for solving some of the problems faced by software developers.

In this second edition, these two trends are clearly highlighted. Aseparate chapter has been included entited "Software Processes." In addition to talking about the various development process models, the chapter discusses other processes in soft­ware development and other issues related to processes. Object-orientation figures in many chapters. Object-oriented analysis is discussed in the chapter on require­ments, while there is a complete chapter entitled "Object-Oriented Design." Some aspects of object-oriented programming are discussed in the chapter on coding, while specific techniques for testing object-oriented programs are discussed in the chapter on testing. Overall, if one wants to develop software using the paradigm of object -orientation, aB aspects of development that require different handling are discussed. Most of the other chapters have also been enhanced in various ways. In particular, the chapters on requirements specification and testing have been considerably enhanced.

The focus of the book remains an introductory course on software engineering; advanced topics are still not included. The basic case study-based approach of the book has been preserved. In addition to the structured design of the case study, the object-oriented design of the case study has been performed, and the design is described in the book. The structured design has now been implemented in C (in the

vi Preface to the Second Edition

first edition the coding was done in Pascal), keeping in mind the growing popularity of the C language in cornmercial establishments. The object-oriented design has been coded in C++. Again, C++ was chosen mostly due to its high availability and popularity. Both the C and C++ code of the case study are available to readers from the horne page for the book.

Metrics-based software development has been steadily gaining importance. This trend has been reftected in the book by placing greater emphasis on the role of metrics in software development. The use of some of the metrics in effecting the development process has been demonstrated on the case study. For example, metrics were used to evaluate, and then change, the design of the case study. Similarly, the C code was evaluated and then changed to reduce the complexity. Tools that were developed for metrics extraction and evaluation are also being made available through the horne page.

A horne page has been created on the Web for this edition of the book, through which some of the documents and code of the case study and some of the tools used can be obtained. The URL of the horne page is

http://www.springer-ny.comlsupplements/jalote/

The following material is available through the horne page (these are discussed at appropriate places in the book):

1. Design specifications for the structured design of the case study (both the initial and the final versions).

2. The C code implementing the final structured design of the case study (both the initial and the final versions).

3. The C++ code implementing the object-oriented design of the case study.

4. The following tools whieh have been used in the case study:

• dmetric-to evaluate the complexity of a design.

• complexi ty-to evaluate the complexity of aC program.

• style-to evaluate the style of aC program.

• ccov-a test coverage analyzer for C programs.

I would like to express my gratitude to many people who readily clarified issues and provided feedback on various parts of the book. These include Frank McGarry; Professors Vietor Basili, Alan Davis, Ginaluigi Caldiera, Harish Karnik, and Mary Jean Harrold; and many others. I am partieularly grateful to Kamal K. Mantri, S. Haripriya, and G. Aditya Kiran for developing the C and C++ code for the case study, developing the tools used for evaluation, and performing experiments with the tools and various designs. I would also like to express my thanks to Infosys Technologies Ltd., Bangalore, where I am spending my sabbatical, for providing the necessary help to finish this edition. Comments about the book are welcome and can be sent by email to [email protected].

Pankaj Jalote

Preface to the First Edition

It is now c1ear that development of large software systems is an extremely complex activity which is full of various opportunities to introduce errors. Software engi­neering is the discipline that attempts to provide methods to handle this complexity and enable us to produce reliable software systems with maximum productivity.

This book offers an integrated approach to software engineering. The "integrated" approach is different from others because the different topics are not covered in isolation. A running case study is employed, which is used throughout the book, illustrating the different activities of software development on the same project. Most ofthe major outputs ofthe project, such as the project plan, design document, code, test plan, test report, and so on, are shown for the case study.

It is important, and very instructive, to not only teach the principles of software engineering but also apply them to a software development project so that all aspects of development can be seen c1early on a project. Such an approach, besides explaining the principles, also offers a case study which can be used as a model for a software development project by a student.

Integration is further achieved by combining software metrics with the different development phases, instead of having aseparate chapter on the subject. It is recognized that metrics are used for controlling and assessing a software project and are employed throughout the life cyc1e. In the book, for each phase, relevant metrics and their use is discussed in the chapter for that phase. This conveys the right idea that metrics is not really a separate topic, complete in itself, but is integrated with the different activities of software development. Similarly, for each phase, quality assurance activities and the control activities that need to be performed while the activities of that phase are being done are described in the chapter for the particular phase.

viii Preface to the First Edition

The sequence of chapters is essentially the same as the sequence of activities performed during software development. All activities, including quality assur­ance and control activities, that should be performed during a particular phase are grouped in one chapter. This is particularly useful for a project-based introductory course in software engineering in which both the students and the instructor can follow the chapters in the order given both in the lectures as weIl as in the project.

This book is for students who have not had previous training in software engi­neering, and it is suitable for a one-semester course. In order to limit the scope of the book and focus it for an introductory course, advanced topics like software reuse, reverse engineering, development environments, and so on, have not been included. It was feit that in an introductory course, rather than trying to give a ftavor of all the topics, it would be best to introduce the student to the discipline of software engineering as weIl as to some of the important topics, and to prepare the student for taking advanced courses in the area of software engineering. This need was further feIt since in the undergraduate computer science curriculum of most universities, the students have no exposure to software engineering prior to the introductory course, and often do not have any other foIlow-up course before they graduate. One of the goals of the book, then, is to include only as much ma­terial as can be covered in a one-semester course, which may be the only software engineering course in a computer science student's education.

I am grateful to my coIleagues Vietor R. Basili and Dieter Rombach for their valuable inputs during the conceptual stages. I am particularly grateful to students in the software engineering courses that I taught at the University of Maryland and the Indian Institute of Technology, Kanpur. Teaching and interacting with the students had a great inftuence on the final form of the book. Students in my course at the Indian Institute of Technology, partieularly Sandeep Sharma and Samudrala Sridhar, deserve special thanks for helping with the case study.

Contents

Preface to the Second Edition

Preface to the First Edition

1 Introduction 1.1 The Software Problem ...... .

1.1.1 Software Is Expensive .. . 1.1.2 Late, Costly, and Unreliable . 1.1.3 Problem of Change and Rework

1.2 Software Engineering Problem . . . 1.2.1 The Problem of Scale . . . . 1.2.2 Cost, Schedule, and Quality . 1.2.3 The Problem of Consistency

1.3 The Software Engineering Approach 1.3.1 Phased Development Process 1.3.2 Project Management and Metrics

1.4 Summary . . . . . . . 1.5 Overview of the Book . Exercises ....

2 Software Processes 2.1 Software Process . . . . . . . . . . . .

2.1.1 Processes, Projects, and Products 2.1.2 Component Software Processes .

2.2 Characteristics of a Software Process 2.2.1 Predictability..........

v

vii

1 2 3 4 5 7 8

10 12 13 13 17 19 19 21

23 23 24 25 28 28

x Contents

2.2.2 Support Testability and Maintainability . . . . 2.2.3 Early Defect Removal and Defect Prevention . 2.2.4 Process Improvement . . . .

2.3 Software Development Process . . . 2.3.1 A Process Step Specification 2.3.2 Waterfall Model. . . . 2.3.3 Prototyping ..... . 2.3.4 Iterative Enhancement 2.3.5 The Spiral Model . . .

2.4 Project Management Process . 2.4.1 Phases of Management Process . 2.4.2 Metrics, Measurement, and Models .

2.5 Software Configuration Management Process . 2.5.1 Configuration Identification . . . 2.5.2 Change Control ........ . 2.5.3 Status Accounting and Auditing

2.6 Process Management Process . . . . . . 2.6.1 Building Estimation Models .. 2.6.2 Process Improvement and Maturity

2.7 Summary Exercises ................... .

3 Software Requirements Analysis and Specification 3.1 Software Requirements . . .

3.1.1 Need for SRS .... 3.1.2 Requirement Process

3.2 Problem Analysis . . . . . 3.2.1 Analysis Issues . . 3.2.2 Informal Approach 3.2.3 Structured Analysis 3.2.4 Object-Oriented Modeling 3.2.5 Other Modeling Approaches 3.2.6 Prototyping.......

3.3 Requirements Specification . . . 3.3.1 Characteristics of an SRS 3.3.2 Components of an SRS . 3.3.3 Specification Languages 3.3.4 Structure of a Requirements Document

3.4 Validation........... 3.4.1 Requirement Reviews . 3.4.2 Other Methods

3.5 Metrics . . . . . . . . 3.5.1 Size Measures . 3.5.2 Quality Metrics

30 32 33 34 34 36 40 43 44 46 47 49 51 53 55 58 59 59 63 69 70

73 74 75 79 83 84 87 87 98

107 115 120 121 123 126 130 133 134 136 137 138 143

Contents xi

3.6 Summary 146 Exercises 147 Case Study .. 150

4 Planning a Software Project 159 4.1 Cost Estimation . . . a •••••••••• 160

4.1.1 Uncertainties in Cast Estimatian 161 4.1.2 Building Cost Estimation Models . 163 4.1.3 On Size Estimation 165 4.1.4 COCOMO Model . 166 4.1.5 An Example .... 169

4.2 Project Scheduling · ... 170 4.2.1 Average Duration Estimation 171 4.2.2 Project Scheduling and Milestones 172 4.2.3 Example Continued . . . 173

4.3 Staffing and Personnel Planning . 173 4.3.1 Rayleigh Curve . . . 174 4.3.2 Personnel Plan ... 176 4.3.3 Example Cantinued . 176 4.3.4 Team Structure ... 178

4.4 Software Configuration Management Plans 179 4.5 Quality Assurance Plans ......... 180

4.5.1 Verification and Validation (V & V) 181 4.5.2 Inspections and Reviews 183

4.6 Project Monitoring Plans 189 4.6.1 Time Sheets . . . . . . . 189 4.6.2 Reviews ......... 190 4.6.3 Cast -Schedule-Milestone Graph 190 4.6.4 Earned Value Method . . 191 4.6.5 Unit Development Folder . . 192

4.7 Risk Management . . . . . . . . . . 193 4.7.1 Risk Management Overview 194 4.7.2 Risk Assessment 196 4.7.3 Risk Control 200

4.8 Summary 201 Exercises .... 202 Case Study Plan . 204

5 Function-Oriented Design 209 5.1 Design Principles · ............ 211

5.1.1 Problem Partitioning and Hierarchy . 212 5.1.2 Abstraction · ............ 214 5.1.3 Modularity · ............ 215 5.1.4 Top-Down and Bottom-Up Strategies . 215

xii Contents

5.2 Module-Level Concepts . 217 5.2.1 Coupling . . . . 217 5.2.2 Cohesion . . . . 218

5.3 Design Notation and Specification 221 5.3.1 Structure Charts. . . . . 222 5.3.2 Specification . . . . . . . 226

5.4 Structured Design Methodology. . 227 5.4.1 Restate the Problem as a Data Flow Diagram . 228 5.4.2 Identify the Most Abstract Input and Output Data

Elements . . . . . . . . . . . . . . . . . . . . . 230 5.4.3 First-Level Factoring . . . . . . . . . . . . . . . 231 5.4.4 Factoring the Input, Output, and Transform Branches. 233 5.4.5 Design Heuristics . . 235 5.4.6 Transaction Analysis 236 5.4.7 Discussion ... 238

5.5 Verification . . . . . . . . . 240 5.5.1 Design Reviews . . . 240 5.5.2 Automated Cross-Checking . 241

5.6 Metrics . . . . . . . . . 242 5.6.1 Network Metrics . . . . . 243 5.6.2 Stability Metrics ..... 244 5.6.3 Information Flow Metrics . 247

5.7 Summary 249 Exercises 251 Case Study .. 253

6 Object-Oriented Design 273 6.1 00 Analysis and 00 Design 274 6.2 Concepts .......... 276

6.2.1 Classes and Objects . 277 6.2.2 Relationships Among Objects . 282 6.2.3 Inheritance and Polymorphism 284 6.2.4 Design Concepts . . . . . 291

6.3 Design Notation and Specification 294 6.4 Design Methodology . . . . 296

6.4.1 Dynamic Modeling . . . . 298 6.4.2 Functional Modeling . . . 301 6.4.3 Defining Internal Classes and Operations 302 6.4.4 Optimize and Package 302 6.4.5 Examples 304

6.5 Metrics 311 6.6 Summary 315 Exercises 316 Case S~udy . . 318

Contents xiii

7 Detailed Design 329 7.1 Module Specifications. . . . . . . . . . 330

7.1.1 Specifying Functional Modules . 331 7.1.2 Specifying Classes 332

7.2 Detailed Design . . . . . . . . . 336 7.2.1 PDL........... 337 7.2.2 Logic/ Algorithm Design 340 7.2.3 State Modeling of Classes . 343

7.3 Verification . . . . . . . . . . 345 7.3.1 Design Walkthroughs . 345 7.3.2 Critical Design Review 345 7.3.3 Consistency Checkers. 347

7.4 Metrics . . . . . . . . . . . . 347 7.4.1 Cyclomatic Complexity . 348 7.4.2 Data Bindings . . 350 7.4.3 Cohesion Metric 351

7.5 Summary 352 Exercises . . . . . . . . . . . 353

8 Coding 355 8.1 Programming Practice. . . . . . . 356

8.1.1 Top-Down and Bottom-Up 357 8.1.2 Structured Programming 358 8.1.3 Information Hiding . . . 361 8.1.4 Programming Style . . . 363 8.1.5 Internal Documentation . 366 8.1.6 Law of Demeter for 00 Programs 366

8.2 Verification . . . . . . 369 8.2.1 Code Reading . . . . 369 8.2.2 Static Analysis .. . 370 8.2.3 Symbolic Execution . 373 8.2.4 Proving Correctness . 378 8.2.5 Code Inspections or Reviews 384 8.2.6 Unit Testing. . 386

8.3 Metrics . . . . . . . . . . . 386 8.3.1 Size Measures. . . . 386 8.3.2 Complexity Metrics . 388 8.3.3 Style Metrics 391

8.4 Summary 393 Exercises 395 Case Study 398

9 Testing 9.1 Testing Fundamentals .

403 404

xiv Contents

9.1.1 EITor, Fault, and Failure ........ . 9.1.2 Test Orades . . . . . . . . . . . . . . . 9.1.3 Top-Down and Bottom-Up Approaches. 9.1.4 Test Cases and Test Criteria . 9.1.5 Psychology ofTesting .....

9.2 Functional Testing. . . . . . . . . . . 9.2.1 Equivalence Class Partitioning 9.2.2 Boundary Value Analysis 9.2.3 Cause-Effect Graphing 9.2.4 Special Cases ..... .

9.3 Structural Testing ....... . 9.3.1 Control Flow-Based Criteria 9.3.2 Data Flow-Based Testing . 9.3.3 An Example ........ . 9.3.4 Mutation Testing . . . . . . 9.3.5 Test Case Generation and Tool Support .

9.4 Testing Object-Oriented Programs 9.4.1 Issues in Testing Classes .... . 9.4.2 State-Based Testing ....... . 9.4.3 Incremental Testing for Subdasses

9.5 Testing Process . . . . . . . . . . . . . . 9.5.1 Comparison of Different Techniques 9.5.2 Levels of Testing . . . . 9.5.3 Test Plan ... . . . . . . . . . . 9.5.4 Test Case Specifications ..... . 9.5.5 Test Case Execution and Analysis.

9.6 Metrics-Reiiability Estimation .... 9.6.1 Basic Concepts and Definitions .. 9.6.2 Musa's Basic Model ...... . 9.6.3 Failure Data and Parameter Estimation 9.6.4 Translating to Calendar Time 9.6.5 An Example .

9.7 Summary Exercises Case Study

References

Index

404 405 407 408 412 412 413 414 415 418 419 419 422 425 428 431 434 435 436 440 442 443 445 447 449 450 453 454 457 461 464 466 467 468 472

481

489