SPECIAL OFFERS
Keep up with new releases and promotions. Sign up to hear from us.
Register your product to gain access to bonus material or receive a coupon.
Putting Metaclasses to Work takes a new, evolutionary look at important concepts of object-oriented programming, starting with the development of an object model from fundamental principles. Unique aspects of this object model include a use of metaclasses to encapsulate the implementation of object properties and a support for reuse of metaclasses. Metaclass reuse is based on a new semantics for inheritance that automatically combines metaclasses by using multiple inheritance to compose object properties.
This book provides a concrete demonstration of how metaclasses can be used to increase productivity and reusability in object-oriented programming. A C++-based language for programming metaclasses according to the authors' model is presented and then used throughout the book, allowing the reader to understand the utility and importance of metaclasses within the overall context of object-oriented programming. In addition, this book:
Preface.
Glossary of Symbols.
1. Introduction.
A Fable.
Dictionaries.
Procedural Specifications.
Exercises.
2. The Elements of Reflective Class-based Models.
The Set of Objects.
A Class Is an Object.
Structure of an Object.
Methods.
Inheritance.
The Top of the Inheritance Hierarchy.
An Initial Environment.
Creating Objects.
Drawing Class Structures.
Metaobject Protocols.
Summary.
Exercises.
3. Inheritance of Metaclass Constraints.
Fundamental Guarantee of Object-Oriented Programming.
Metaclass Incompatibility.
Metaclass Constraints.
Importance of Inheriting Metaclass Constraints.
From the Programmer's Point of View.
Epistemological Argument for Inheritance of Metaclass Constraints.
On Metaclasses That Invoke Instance Methods.
Summary.
Exercises.
4. Dynamic Aspects of Our Object Model.
Method Invocation.
Instance Variable Access.
Instance Initialization.
Conservative Merge.
Method Resolution Order.
Class Construction.
Parent Method Call.
Cooperative Override Methods.
Serious Order Disagreements.
A Simple Programming Model.
Monotonicity of Implementation Chains.
Summary.
Exercises.
5. DTS C++.
C++ Basics.
DTS C++ Basics.
Graph Versus Tree Inheritance.
Typechecking.
Summary.
Exercises.
6. Our Metaobject Protocol.
Interface to Our Metaobject Protocol.
Object Creation.
Retrieving the Class of an Object.
Freeing Objects.
Initializing Classes.
Solving a Set of Metaclass Constraints.
Defining Methods of a Class.
Readying a Class.
Example: a Metaclass for Managing the Extent of a Class.
Invoking Methods from Interpreters.
Instance Variable Access.
Example: Creation Time Stamps.
Redispatching a Method.
Summary.
Exercises.
7. Cooperation among Metaclasses.
Requirements for Cooperative Metaclasses.
Metaclass for Cooperation.
Notes on the Design of Cooperation.
Conflicts and Library Design.
A Discussion of Parameter Passing.
A Metaclass for Redispatching All Methods.
Example: A Simple Trace Facility.
Summary.
Exercises.
8. Before/After Metaclasses.
The Composition Problem.
Design of the Before/After Metaclass.
Discussion.
Example: A Simple Metaclass for Thread Safety.
Summary.
Exercises.
9. Proxies.
The Purpose of Proxies.
Design of a Proxy Metaclass.
Properties of Proxies.
Distributed Systems.
Extent Managed Proxies.
Summary.
Exercises.
10. Metaclasses for Frameworks.
Invariant Checking.
Single Instanced Property.
The Abstract Property.
The Final Property.
Mixins.
Preventing Parent Method Calls.
Summary.
Exercises.
11. Release-to-Release Binary Compatibility.
The Library Compatibility Problem.
Defining Release-to-Release Binary Compatibility.
Procedural Programming.
Object-Oriented Programming.
When Classes are First-Class Objects.
A Comparison of Support in Several Object Models.
Completeness of a Set of Transformations.
Summary.
12. Conclusion.
Contributions of This Book.
Summary.
Appendix A: Advanced Linearization.
Properties of Linearizations.
The Limits of Linearization.
Summary.
Exercises.
Appendix B: Handling Apply and Redispatch Stubs.
Enhanced Control over Method Dispatch.
Example of an Apply Stub.
Example of a Redispatch Stub.
Appendix C: Rationale for Drawing Conventions.
Appendix D: Answers to Selected Exercises.
Bibliography.
Index. 0201433052T04062001
In object-oriented programming, objects are created as instances of classes. This book deals with the kind of object model in which classes are themselves objects (that is, classes are created as instances of other classes). We have discovered the key to designing such a model so as to improve markedly the levels of composability and reusability attainable in object-oriented programming. Our goal in writing this book is to convey our discovery to others interested in object-oriented programming.
If one thinks of objects as cookies, then classes are analogous to cookie cutters. Cookie cutters are templates that are used to make and determine the properties of cookies; classes make and determine the properties of objects. But how are cookie cutters themselves made? Let us say that they are pressed from sheet metal using a cookie cutter press (a piece of heavy machinery). So, if a cookie cutter press is used to make cookie cutters, what is used to make classes? The answer is a metaclass. Although a cookie cutter press does not directly make cookies (because it makes cookie cutters), it does determine properties of cookies. In a very similar way, a metaclass can determine the properties of objects, because it builds a class that makes objects. Our solution for greater reusability is based on the use of metaclasses to isolate and implement object properties.
Metaclasses alone are not enough to attain the improved levels of composability and reusability. This book introduces a new kind of object model called a monotonic reflective class-based model. In this new model, inheritance extends beyond instance variables and methods into a new dimension in which the relationship between a class and its metaclass is also inherited. This extension, called inheritance of metaclass constraints, is our key discovery. In the resulting technology, not only can metaclasses isolate and implement individual properties, but the composition of the metaclasses isolates and implements the composite property. That is, if one metaclass implements property P while another implements property Q, the composite metaclass implements the property P and Q. This degree of composability does not happen by accident; it is engineered by the proper design of metaclasses and other primitive capabilities within our technology.
In the course of developing the abovementioned ideas, this book explains concepts that are generally useful to and appreciated by anyone interested in object-oriented programming. This book develops object technology from first principles. In doing so, it motivates and demystifies metaclasses, shows how to construct them and compose them, and presents examples of their use. By reading this book, you will learn not only our technology but also the general principles of reflection in object technology.
This book returns to the source of power of object-oriented programming--the synergy of knowledge representation and programming--to yield a major improvement. Consider the following linguistic interpretation of the evolution of computer programming. In the 1950s and 1960s, programming was about commanding the computer--verbs. In the 1970s, this approach proved deficient. A new paradigm arose in which the specification of abstract data types and then classes--nouns--became foremost for the programmer. This paradigm, object-oriented programming, has evolved throughout the 1980s and 1990s. Although powerful and useful, object-oriented programming has proved deficient in isolating properties of objects--adjectives--so that the code that implements a property can be reused. Our technology has an abstraction for adjectives (metaclasses) to complement the nouns (classes) and verbs (methods) of today's object technology. Furthermore, as we will show, composition of metaclasses is as easy as putting a sequence of adjectives in front of a noun when we speak.
This book presents new techniques in object-oriented programming, and you have the right to ask our basis for claiming that these techniques are effective. We developed and used these techniques over a four-year period in the evolution of IBMis SOMobjects Toolkit. Most of the important metaclasses described in this book are based on metaclasses implemented in IBMis SOMobjects Toolkit 3.0, although not all of them have publicly available interfaces (those without public interfaces are used to program other parts of the toolkit). All of these metaclasses have been used by the authors or other SOM programmers to write real programs.
The metaclasses of IBMis SOMobjects Toolkit 3.0 are written using the toolkitis metaobject protocol. To make this book as readable as possible, we have simplified that protocol. In addition, we have taken the opportunity in writing this book to improve the toolkitis metaobject protocol. Because of these two factors, our metaobject protocol (the one in this book) is SOM-like, but is not SOM.
Because we have deviated from IBMis SOMobjects Toolkit 3.0 in this book, we have provided a simulation of the object model, our metaobject protocol, and an implementation of all metaclasses in this book that runs on the object model simulation. This is programmed in Java (because of its portability) and can be downloaded from the following URL http://www.awl.com/cseng/titles/0-201-43305-2. Consult the ireadmei file for further information about the simulation.
This book is intended for programmers, researchers in object-oriented programming, and students in computer science. It is written at the level of senior undergraduates studying computer science. There are two prerequisites for reading this book:
Throughout the six years of work that led to this book, we have benefited from discussions with and comments from many friends and colleagues. We thank Liane Acker, Govind Balakrishnan, Arindam Banerji, Michael Cheng, Ravi Condamoor, Mike Conner, George Copeland, Diane Copenhaver, Brad Cox, Nissim Francez, Kevin Greene, Ted Goldstein, Mike Heytens, Duane Hughes, Shmuel Katz, Gregor Kiczales, Donovan Kolbly, Hillel Kolodner, Vinoj Kumar, John Lamping, Rene Llames, Hari Madduri, Andy Martin, Simon Nash, Harold Ossher, Andy Palay, Jim Platt, Tom Pennello, Larry Raper, Cliff Reeves, Charlie Richter, Brian Ritter, Frederick Rivard, Kim Rochat, Jerry Ronga, Roger Sessions, Erin Shepler, Marc Smith, Robert Stroud, Brian Watt, and Cun Xiao for their aid in achieving our goal. Special thanks go to Derek Beatty, David Boles, Michael Cheng, Nathaniel Forman, John Lamping, Doug Lea, Charlie Richter, Leick Robinson, Brett Schuchert, Kent Spaulding, and Gerhart Werner for their comments on the draft of this book. Special acknowledgment must go to the designers and implementors of the original version of SOM: Mike Conner, Andy Martin, and Larry Raper.