{"product_id":"design-by-contract-by-example","title":"Design by Contract: By Example","description":"\u003cp\u003e\u003cstrong\u003eBook info:\u003c\/strong\u003e Design by Contract: By Example (Paperback, 238 pages) – Addison-Wesley Publishing Company, 2001. Language: English.\u003c\/p\u003e\n The first book of its kind to offer an example based approach to learning. If you are a developer seeking a way to improve your craft, this book will give you the necessary understanding of the concepts of contracts in software design. Softcover.  \n        Excerpt. © Reprinted by permission. All rights reserved.   WHAT THE BOOK COVERS\u003cp\u003eDesign 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:\u003c\/p\u003e\u003cul\u003e\n\u003cli\u003e A precondition is a condition on a method specifying what must be true for it to be valid to call the method.\u003c\/li\u003e\n\u003cli\u003e A postcondition is a condition on a method specifying what will become true when the method successfully completes.\u003c\/li\u003e\n\u003cli\u003e 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.\u003c\/li\u003e\n\u003c\/ul\u003e\u003cp\u003eThe assertions are written in a programming language, so that\u003c\/p\u003e\u003cul\u003e\n\u003cli\u003e They make sense to programmers, providing good, helpful documentation.\u003c\/li\u003e\n\u003cli\u003e They can be checked at runtime, providing support for testing and debugging.\u003c\/li\u003e\n\u003c\/ul\u003e\u003cp\u003eThis 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.\u003c\/p\u003e\u003cp\u003eAfter 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.\u003c\/p\u003e\u003cp\u003eIn 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.\u003c\/p\u003ePROGRAMMING LANGUAGES\u003cp\u003eThe examples are presented first in the object-oriented programming language Eiffel. We chose Eiffel for three reasons:\u003c\/p\u003e\u003cli\u003eEiffel has built-in support for contracts, so it is excellent for showing the concepts at work. \u003c\/li\u003e\u003cli\u003e 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.\u003c\/li\u003e\u003cli\u003e 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.\u003c\/li\u003e\u003cp\u003eYou 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.\u003c\/p\u003e\u003cp\u003eWe 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.\u003c\/p\u003eWHO THE BOOK IS FOR\u003cp\u003eThe 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.\u003c\/p\u003e\u003cp\u003eWe 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).\u003c\/p\u003e\u003cp\u003eWe 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.\u003c\/p\u003eSTYLE\u003cp\u003eThe 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.\u003c\/p\u003e\u003cp\u003eThe 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.\u003c\/p\u003e\u003cp\u003eWe 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.\u003c\/p\u003e\u003cp\u003eAnd, 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.\u003c\/p\u003eWEB SITE\u003cp\u003eThere 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.\u003c\/p\u003e \u003cbr\u003e \u003cbr\u003e 0201634600P12122001       ","brand":"Richard Mitchell, Jim McKim, Bertrand Meyer","offers":[{"title":"Default Title","offer_id":46070013788394,"sku":"9780201634600","price":57.98,"currency_code":"USD","in_stock":true}],"thumbnail_url":"\/\/cdn.shopify.com\/s\/files\/1\/0714\/5301\/6298\/files\/31CiQn-NeLL._SL1500.jpg?v=1781237535","url":"https:\/\/textbookme.store\/products\/design-by-contract-by-example","provider":"TextbookMe","version":"1.0","type":"link"}