Jean-Marc Jézéquel, Michel Train, and Christine Mingins' Design Patterns and Contracts is about the use of contracts with design patterns. Patterns were first introduced in Design Patterns: Elements of Reusable Object-Oriented Software (Addison-Wesley Longman, 1995) by the "Gang of Four" (GoF)—Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides—as a means of capturing and leveraging best design practices. Contracts were first introduced in Applying "Design by Contact" by Bertrand Meyer (IEEE Computer, October 1992) and implemented in the Eiffel computer language to add consistency conditions for building more robust systems. The ideas in Design Patterns and Contracts should be of interest to anyone focused on building higher quality software systems.
The book is composed of three parts. Part I introduces patterns and contracts. Part II explains the GoF patterns with contracts. Part III demonstrates the use of patterns on various problems.
Chapter 1 introduces patterns and how they can be applied throughout the life cycle. Patterns are generalized solutions to problems in a given context, where each pattern has a description of the problem, solution, and the context in which it applies. A solution is described using a static structure (identifying the participating elements and their relationships) and a dynamic structure (identifying how the elements collaborate). This chapter is excellent in delineating among architectural patterns, design patterns, idioms, and how patterns generally relate to frameworks. Also, the GoF template for capturing patterns and the Object Management Group's standardized Unified Modeling Language for communicating the static structure and dynamic structure of patterns are briefly discussed.
Chapter 2 introduces contacts and Design by Contract. Contracts are descriptions of obligations among clients who utilize the services provided by suppliers. Design by Contract is a technique where pre-conditions, post-conditions, and invariants are used to define contracts. Pre-conditions are Boolean assertions that a client must satisfy before requesting a service. Post-conditions are Boolean assertions that a supplier must satisfy after providing a service. Invariants are Boolean assertions that must be satisfied over time. This chapter presents a good introduction to Design by Contract and some of the Eiffel language syntax.
Chapters 3, 4, and 5 present the GoF creational, structural, and behavioral patterns. Creational patterns are concerned with decoupling the type of an object from the process of constructing objects of that type. Structural patterns are concerned with larger structures composed of smaller structures. Behavioral patterns are concerned with assigning responsibilities among a collection of objects. Each pattern is identified with the page number showing where it appears in the original GoF book, including its intent, static structure, dynamic structure, an Eiffel implementation demonstrating the pattern and the use of contracts, and references to related patterns. These chapters provide an excellent source for reference.
Chapter 6 discusses a case study that demonstrates how to apply patterns to simplify software configuration management. Chapter 7 demonstrates how to apply patterns for building graphical user interfaces. These chapters provide a good discussion on, and demonstration of, the use of patterns and contracts.
Design Patterns and Contracts is a book whose time has come. It demonstrates how contracts contribute to design patterns. Even if you are not interested in the Eiffel language, the concepts and information in this book apply to virtually any computer programming language.
Sinan Si Alhir is a consultant and author of UML in a Nutshell (O'Reilly & Associates, 1998). Reach him at salhir@earthlink.net or visit his Web site at home.earthlink.net/~salhir.