Adaptive Object-Oriented Software: The Demeter Method with Propagation Patterns Foreword by Gregor Kiczales and John Lamping ============================================ As we write this foreword, it is Earth day, a day to think about the interrelatedness of life on Earth. It is a day to contemplate that while each living thing is an individual organism, all the organisms in an eco-system are connected by a complex web of interaction, upon which they all depend for their continuing existence. One of the main lessons of ecology is that while it is comparatively easy to isolate, identify and categorize individual organisms, the relationships among them are much more difficult to identify and don't fall into nicely separated categories. Object-oriented programs are much simpler than natural ecosystems---even though a programmer trying to chase down a recalcitrant bug might be inclined to disagree---but they have a similar structure. Like ecosystems, they are composed of individuals, objects in this case. Also like ecosystems, the behavior of the system arises out of the inter-relationships and interactions of those individuals. Object-oriented design recognizes this interdependence, and uses notations like class graphs to help describe the relationships among the objects. Because these relationships among objects are so important, their design is one of the first steps in a typical object-oriented design. The detailed design of the individual objects or classes only happens once a system design is in place. But because the inter-relationships among objects are complex, it is almost impossible to design them exactly right the first time, as anyone who has built a reasonably large object-oriented program knows from hard-won experience. The design process is iterative, with the interactions among objects being redesigned as problems are uncovered during design or coding of individual objects or classes. And the design process is only the beginning of changes to the interactions. Other changes will be necessary during maintenance as the system evolves to meet changing requirements, and still more changes will be necessary if parts of the system are reused for other applications. Traditional object-oriented programming has been a great success, partly because of the kinds of flexibility that object encapsulation provides. But it doesn't provide comparable support for flexibility in object inter-relationships. For example, object-oriented languages require coding in the smallest details of the relationships among objects, such as navigation paths among interacting objects. Often a great deal of code needs to be edited in the face of even a small change to the conceptual interdependence structure. There are similar challenges for flexibility in what class should be used for newly created objects, and in allowing different parts of an evolving program to have different viewpoints on the same object. Adaptive object-oriented programming allows programs to be written in a way that makes them less brittle in the face of these changes. Adaptive object-oriented programming works by having the programmer program at a higher, schematic, level that abstracts away from details like navigation paths. These schematic patterns can be instantiated to a particular class graph to get an executable program. In this way it is a kind of meta-programming. In many cases, programs can be adapted to new situations simply by changing the instantiation of the schematic patterns, without having to change the high-level program. By thinking in terms of this higher level of abstraction, the programmer can write code that is both simpler and more tolerant of changes. This book presents a complete, well-worked-out methodology for adaptive programming in C++ and tools for supporting the methodology. And because the methodology is programming language independent, any programmer interested in writing cleaner, more flexible OBJECT-ORIENTED code should read this book. We hope the work presented in this book will become one of the building blocks for a new trend in object-oriented programming, a trend that takes the next step beyond object encapsulation to provide new abstraction tools for the interaction among objects. Palo Alto, California April 1995 Gregor Kiczales John Lamping Xerox PARC