MTU Library Catalogue

Syndetics cover image
Image from Syndetics

Design by contract, by example / Richard Mitchell and Jim McKim.

By: Mitchell, R. (Richard), 1947-.
Contributor(s): McKim, Jim.
Material type: materialTypeLabelBookPublisher: Harlow : Addison-Wesley, c.2002Description: xv, 238 p. ; 24 cm.ISBN: 0201634600; 9780201634600.Subject(s): Component software | Object-oriented programming (Computer science) | Computer-aided design | Object-oriented programming (OOP) | Computer architecture & logic design | Computers and ITDDC classification: 005.117 MIT Summary: Design by Contract is a general approach to software design that dramatically improves the quality of the resulting products. This book provides an example-based approach to learning the powerful concept of Design by Contract.
Holdings
Item type Current library Call number Copy number Status Barcode
General lending MTU Kerry North Campus Library Ground Floor Main 005.117 MIT (Browse shelf(Opens below)) 1 Available 38888000544688
Total holds: 0

Enhanced descriptions from Syndetics:

Programming by contract is a powerful object-oriented technique that provides a disciplined and effective means of documenting the public interface of a class. This text provides a detailed description of programming by contract and demonstrates how to exploit its full power. The core of the text consists of a collection of design principles that the author has developed, and an array of examples from the Eiffel Library Kernal Standard (ELKS) is included.

Includes bibliographical references (p. 227-230) and index.

Design by Contract is a general approach to software design that dramatically improves the quality of the resulting products. This book provides an example-based approach to learning the powerful concept of Design by Contract.

Table of contents provided by Syndetics

  • Foreword (p. ix)
  • Preface (p. xi)
  • Chapter 1 A First Taste of Design by Contract (p. 1)
  • 1.1 About This Chapter (p. 1)
  • 1.2 The Customer Manager Example (p. 2)
  • 1.3 Some Questions (p. 5)
  • 1.4 A Contract for CUSTOMER_MANAGER (p. 6)
  • 1.5 The Story So Far (p. 9)
  • 1.6 Runtime Checking (p. 11)
  • 1.7 Trustworthy Documentation (p. 13)
  • 1.8 Summary (p. 15)
  • 1.9 An Aide Memoire (p. 15)
  • 1.10 Things to Do (p. 15)
  • Chapter 2 Elementary Principles of Design by Contract (p. 17)
  • 2.1 About This Chapter (p. 17)
  • 2.2 Stacks (p. 18)
  • 2.3 Separate Commands and Queries (p. 19)
  • 2.4 Naming Conventions (p. 22)
  • 2.5 Separate Basic Queries and Derived Queries (p. 23)
  • 2.6 Specify How Commands Affect Basic Queries (p. 26)
  • 2.7 Capture Unchanging Properties in Invariants (p. 34)
  • 2.8 The Class and Its Contract (p. 36)
  • 2.9 The Basic Queries Are a Conceptual Model of Stacks (p. 38)
  • 2.10 The Six Principles (p. 42)
  • 2.11 Things to Do (p. 43)
  • Chapter 3 Applying the Six Principles (p. 47)
  • 3.1 About This Chapter (p. 47)
  • 3.2 Dictionaries (p. 47)
  • 3.3 Separating and Categorizing Features (p. 48)
  • 3.4 Postconditions (p. 50)
  • 3.5 Preconditions (p. 56)
  • 3.6 Invariant (p. 62)
  • 3.7 A Complete, Contract-Level View of DICTIONARY (p. 63)
  • 3.8 Summary (p. 65)
  • 3.9 Things to Do (p. 66)
  • Chapter 4 Building Support for Contracts--Immutable Lists (p. 69)
  • 4.1 About This Chapter (p. 69)
  • 4.2 Support for Linear Structures (p. 69)
  • 4.3 Contracts Involve Expressions (p. 70)
  • 4.4 Immutable Lists (p. 71)
  • 4.5 A Contract for Immutable Lists (p. 72)
  • 4.5.1 The Basic Queries (p. 72)
  • 4.5.2 The Creation Command (p. 74)
  • 4.5.3 The Derived Query count (p. 74)
  • 4.5.4 The Derived Query preceded_by (p. 74)
  • 4.5.5 The Derived Query item (p. 75)
  • 4.5.6 The Derived Query is_equal (p. 77)
  • 4.5.7 The Derived Query sublist (p. 79)
  • 4.6 Summary (p. 81)
  • 4.7 Things to Do (p. 81)
  • Chapter 5 Applying the Six Principles to QUEUE (p. 83)
  • 5.1 About This Chapter (p. 83)
  • 5.2 Queues (p. 83)
  • 5.3 A Contract for the remove Feature (p. 84)
  • 5.4 Making count a Derived Feature (p. 88)
  • 5.5 A Contract for the Initialize Feature (p. 91)
  • 5.6 A Contract for the head Feature (p. 93)
  • 5.7 A Contract for the put Feature (p. 94)
  • 5.8 More Derived Queries (p. 94)
  • 5.9 Summary (p. 95)
  • 5.10 Things to Do (p. 96)
  • Chapter 6 Design by Contract and Inheritance (p. 99)
  • 6.1 About This Chapter (p. 99)
  • 6.2 Superclasses and Subclasses (p. 99)
  • 6.3 Redefining Contracts (p. 100)
  • 6.3.1 Eiffel Syntax (p. 104)
  • 6.3.2 Summary (p. 107)
  • 6.4 Invariants and Inheritance (p. 108)
  • 6.5 Designing Superclasses with Guarded Postconditions (p. 109)
  • 6.6 Two Kinds of Inheritance (p. 116)
  • 6.7 Summary (p. 117)
  • 6.8 Things to Do (p. 117)
  • Chapter 7 Frame Rules (p. 119)
  • 7.1 About This Chapter (p. 119)
  • 7.2 Change Specifications and Frame Rules (p. 119)
  • 7.3 Frame Rules for put Using Immutable Lists (p. 121)
  • 7.4 Frame Rules for put Using "Forall" (p. 128)
  • 7.5 Kinds of Frame Rules (p. 130)
  • 7.6 Things to Do (p. 132)
  • 7.7 Appendix: More About the Preprocessor (p. 132)
  • Chapter 8 Benefits of Design by Contract (p. 137)
  • 8.1 About This Chapter (p. 137)
  • 8.2 Kinds of Benefits (p. 137)
  • 8.3 Better Designs (p. 138)
  • 8.4 Improved Reliability (p. 140)
  • 8.5 Better Documentation (p. 140)
  • 8.6 Easier Debugging (p. 142)
  • 8.7 Support for Reuse (p. 142)
  • 8.8 Design by Contract and Defensive Programming (p. 143)
  • 8.8.1 Defending a Program Against Unwanted Input (p. 143)
  • 8.8.2 Bulletproofing a Routine (p. 144)
  • 8.8.3 Defensive Programming (p. 145)
  • 8.9 Some Costs and Limitations of Contracts (p. 146)
  • Chapter 9 Contracts for an Observer Framework (p. 149)
  • 9.1 About This Chapter (p. 149)
  • 9.2 The Observer Framework (p. 150)
  • 9.3 Immutable Sets (p. 152)
  • 9.4 Attaching and Detaching Observers (p. 155)
  • 9.5 Notification (For One Observer) (p. 156)
  • 9.6 Notification (For All Observers) (p. 158)
  • 9.7 A Performance Issue (p. 160)
  • 9.8 Frame Rules (p. 161)
  • 9.9 Privacy (p. 164)
  • 9.10 Things to Do (p. 166)
  • Chapter 10 Fulfilling a Precondition (p. 169)
  • 10.1 About This Chapter (p. 169)
  • 10.2 The Examples (p. 170)
  • 10.3 Fulfilling and Testing a Precondition (p. 170)
  • 10.4 Testing Versus Checking (p. 172)
  • 10.5 A Simple Counter Class (p. 173)
  • 10.6 The User's View of the Program (p. 174)
  • 10.7 The Internal Structure of the Program (p. 176)
  • 10.8 The Program's Behavior (p. 178)
  • 10.9 A Minor Detail (p. 184)
  • 10.10 Summary (p. 186)
  • 10.11 Things to Do (p. 187)
  • Chapter 11 Java Examples (p. 189)
  • 11.1 About This Chapter (p. 189)
  • 11.2 Why Java? (p. 190)
  • 11.3 Queues (p. 190)
  • 11.3.1 The Basic Query size() (p. 192)
  • 11.3.2 The Basic Query get() (p. 193)
  • 11.3.3 The Derived Query head() (p. 193)
  • 11.3.4 The Derived Query isEmpty() (p. 194)
  • 11.3.5 The Derived Query shallowCopy() (p. 194)
  • 11.3.6 The Constructor Queue (p. 195)
  • 11.3.7 The Command put (p. 196)
  • 11.3.8 The Command remove (p. 196)
  • 11.3.9 Summary (p. 198)
  • 11.4 Dictionaries (p. 198)
  • 11.4.1 Names (p. 199)
  • 11.4.2 The Invariant (p. 200)
  • 11.4.3 The Basic Queries (p. 200)
  • 11.4.4 A Derived Query (p. 201)
  • 11.4.5 The Commands (p. 201)
  • 11.4.6 The Constructor (p. 202)
  • 11.4.7 A Possible Set of Classes (p. 203)
  • 11.5 Java Without iContract (p. 203)
  • 11.6 Precondition Testing (p. 207)
  • 11.7 Things to Do (p. 212)
  • Chapter 12 Analysis by Contract (p. 215)
  • 12.1 About This Chapter (p. 215)
  • 12.2 A Use Case (p. 215)
  • 12.3 Contracts in Analysis Models (p. 217)
  • 12.4 A Contract for the withdrawCash Use Case (p. 217)
  • 12.5 From Analysis to Design (p. 220)
  • 12.6 Problem Domain and System Models (p. 221)
  • 12.7 The Object Constraint Language (p. 224)
  • 12.8 Summary (p. 225)
  • Bibliography (p. 227)
  • Index (p. 231)

Excerpt provided by Syndetics

WHAT THE BOOK COVERS Design by contract is all about adding assertions to object-oriented programs, at the design and coding stages. Assertions are facts about a program that must be true for the program to be bug-free. The key assertions in design by contract define preconditions, postconditions, and invariants: A precondition is a condition on a method specifying what must be true for it to be valid to call the method. A postcondition is a condition on a method specifying what will become true when the method successfully completes. An invariant is a condition on a whole class specifying what is true about any object of the class whenever you can call a method on that object. The assertions are written in a programming language, so that They make sense to programmers, providing good, helpful documentation. They can be checked at runtime, providing support for testing and debugging. This book concentrates on showing you how to write good contracts. The book presents six principles for writing good contracts, and some supporting guidelines. Through examples, the book motivates the principles and guidelines and shows them in use. After studying the first three chapters, you will be in a position to write high-quality contracts. The rest of the book will help you do even better. In addition to chapters that develop contracts for individual example classes, there are chapters on contracts in relation to inheritance and on the topic of frame rules (contracts that assert what does not change). Two larger examples towards the end of the book involve developing contracts across more than one class. Chapter 9 concerns the Observer pattern from Gamma et al. 1994, and Chapter 10 presents a small application in which an object in the user interface is shown to respect part of a contract in the heart of the application. Chapter 12 discusses the use of contracts in systems analysis. Chapter 8 reviews the benefits of using contracts and compares design by contract to defensive programming. Chapter 11 explores how to attach contracts to interfaces and explores briefly how you might implement contracts in a distributed environment. PROGRAMMING LANGUAGES The examples are presented first in the object-oriented programming language Eiffel. We chose Eiffel for three reasons: Eiffel has built-in support for contracts, so it is excellent for showing the concepts at work. Eiffel is easy to read, so it's a good pseudo-code from which you can implement the ideas in any object-oriented programming language. Commercial-strength compilers are available for Eiffel, so our contracts can play both their intended roles, as specifications and as checks. A contract is a specification of a class, describing precisely what services the class delivers. The assertions in a contract can be evaluated at runtime to check that the implementing code is consistent with its specification. You don't have to be an Eiffel programmer to follow the examples. We are sure you'll be able to carry the principles over to your own programming environment. The issues we raise, and the advice we give, are not specific to Eiffel. We do rework two of our examples in Java, using a preprocessor (called iContract) that provides support for contracts. This allows us to explore some issues that do not arise so directly in Eiffel and to show you contracts in another language. WHO THE BOOK IS FOR The book is written for anyone who wants to find out how to write good contracts. We intend it to be useful to practitioners, students (especially the early chapters), teachers, and researchers. We don't believe the book is one you can curl up with by the fire (in winter) or the pool (in summer) and read your way through. We believe its material has to be studied and, most importantly, tried out. We hope you have access to a programming environment that supports contracts, such as a Java compiler and the iContract tool (see the bibliography for more information) or an Eiffel compiler (again, more information in the bibliography). We do not teach object-oriented programming. We assume you know how to program in some object-oriented programming language. We have tried to give enough explanation of the Eiffel and Java code that those familiar with other OO languages can follow the examples. STYLE The book is based firmly on examples. Usually, a chapter is based on a single example. This means that there is quite a lot of code to wade through at times. However, most of the code is at the level of assertions, which define what a piece of program achieves. This level of code is generally easier to understand than the code that defines how a piece of program achieves its goal. In addition, we usually dissect the code a few lines at a time to make it easier to follow the discussion. The examples are mostly simple ones. For example, instead of writing full contracts for the customer manager component introduced in Chapter 1, we write them for a look-up table (or dictionary), which is the data structure that underpins the customer manager component. That way, you won't get lost in too many details, and you won't lose sight of the basic principles. Once you see the principles, we are confident you'll be able to apply them to your own, more complicated examples. We have been selective in what we put into this book. Other books have useful and insightful things to say on the subject of design by contract, but we have concentrated on what makes this book different--the advice it gives on how to write good contracts. And, of course, this book is not the end of the story of design by contract. There is more work to be done on writing contracts, on developing the underlying technology and the underlying theory, on applying the ideas in broader contexts, and on assessing the benefits in practice. WEB SITE There is a Web site associated with the book. It contains the source code of the examples. Our hope is that you will download the code and play with it. Change the code. Add bugs, both in the implementation and in the contracts, and see what happens. Change the examples into new ones. Experiment. Use them on real projects. That's how we learned about contracts. 0201634600P12122001 Excerpted from Design by Contract, by Example by Jim McKim, Richard Mitchell All rights reserved by the original copyright owners. Excerpts are provided for display purposes only and may not be reproduced, reprinted or distributed without the written permission of the publisher.

Author notes provided by Syndetics

Richard Mitchell is a senior consultant with InferData Corporation, specializing in object-oriented analysis and design. Before joining InferData full-time in 1999, he was a Professor of Computing at the University of Brighton, UK, where he was involved in teaching and researching object technology.

Jim McKim is Clinical Professor and Chair of the Department of Engineering and Science at Rensselaer Polytechnic Institute in Hartford, Connecticut. He has been teaching and consulting in the area of object oriented software development for some 10 years. Over the same period he has authored or coauthored numerous articles on Design by Contract for such publications as the Journal of Object-Oriented Programming and IEEE Computer.



0201634600AB08142001