The evolution of the Component Object Model (COM) has in many ways paralleled the evolution of C++. Both movements shared a common goal of achieving better reuse and modularity through refinements to an existing programming model. In the case of C++, the preceding model was procedural programming in C, and C++'s added value was its support for class-based object-oriented programming. In the case of COM, the preceding model was class-based programming in C++, and COM's added value is its support for interface-based object-oriented programming.
As C++ evolved, its canon evolved as well. One notable work in this canon was Scott Meyers' Effective C++. This text was perhaps the first text that did not try to teach the reader the basic mechanics and syntax of C++. Rather, Effective C++ was targeted at the working C++ practitioner and offered 50 concrete rules that all C++ developers should follow to craft reasonable C++-based systems. The success of Effective C++ required a critical mass of practitioners in the field working with the technology. Additionally, Effective C++ relied on a critical mass of supporting texts in the canon. At the time of its initial publication, the supporting texts were primarily The C++ Programming Language by Stroustrup and The C++ Primer by Lippman, although a variety of other introductory texts were also available.
The COM programming movement has reached a similar state of critical mass. Given the mass adoption of COM by Microsoft as well as many other development organizations, the number of COM developers is slowly but surely approaching the number of Windows developers. Also, five years after its first public release, there is finally a sufficiently large canon to lay the tutorial groundwork for a more advanced text. To this end, Effective COM represents a homage to Scott Meyers' seminal work and attempts to provide a book that is sufficiently approachable that most working developers can easily find solutions to common design and coding problems.
Virtually all existing COM texts assume that the reader has no COM knowledge and focus most of their attention on teaching the basics. Effective COM attempts to fill a hole in the current COM canon by providing guidelines that transcend basic tutorial explanations of the mechanics or theory of COM. These concrete guidelines are based on the authors' experiences working with and training literally thousands of COM developers over the last four years as well as on the communal body of knowledge that has emerged from various Internet-based forums, the most important of which is the DCOM mailing list hosted at DCOM-request@discuss.microsoft.com.
This book owes a lot to the various reviewers who offered feedback during the book's development. These reviewers included Saji Abraham, David Chappell, Steve DeLassus, Richard Grimes, Martin Gudgin, Ted Neff, Mike Nelson, Peter Partch, Wilf Russell, Ranjiv Sharma, George Shepherd, and James Sievert. Special thanks go to George Reilly, whose extensive copyediting showed the authors just how horrible their grammar really is. Any errors that remain are the responsibility of the authors. You can let us know about these errors by sending mail to effectiveerrata@develop.com. Any errata or updates to the book will be posted to the book's Web page, http://www.develop.com/effectivecom.
The fact that some of the guidelines presented in this book fly in the face of popular opinion and/or "official" documentation from Microsoft may at first be confusing to the reader. We encourage you to test our assertions against your current beliefs and let us know what you find. The four authors can be reached en masse by sending electronic mail to effectivecom@develop.com.
Intended Audience
This book is targeted at developers currently using the Component Object Model and Microsoft Transaction Server (MTS) to develop software. Effective COM is not a tutorial or primer; rather, it assumes that the reader has already tackled at least one pilot project in COM and has been humbled by the complexity and breadth of distributed object computing. This book also assumes that the reader is at least somewhat familiar with the working vocabulary of COM as it is described in Essential COM. The book is targeted primarily at developers who work in C++; however, many of the topics (e.g., interface design, security, transactions) are approachable by developers who work in Visual Basic, Java, or Object Pascal.
What to Expect
The book is arranged in six chapters. Except for the first chapter, which addresses the cultural differences between "100% pure" C++ and COM, each chapter addresses one of the core atoms of COM.
Shifting from C++ to COM
Developers who work in C++ have the most flexibility when working in COM. However, it is these developers who must make the most adjustments to accommodate COM-based development. This chapter offers five concrete guidelines that make the transition from pure C++ to COM-based development possible. Aspects of COM/C++ discussed include exception handling, singletons, and interface-based programming.
Interfaces
The most fundamental atom of COM development is the interface. A well-designed interface will help increase system efficiency and usability. A poorly designed interface will make a system brittle and difficult to use. This chapter offers 12 concrete guidelines that help COM developers design interfaces that are efficient, correct, and approachable. Aspects of interface design discussed include round-trip optimization, semantic correctness, and common design flaws.
Implementations
Writing COM code in C++ requires a raised awareness of details, irrespective of the framework or class library used to develop COM components. This chapter offers 11 concrete guidelines that help developers write code that is efficient, correct, and maintainable. Aspects of COM implementation discussed include reference counting, memory optimization, and type-system errors.
Apartments
Perhaps one of the most perplexing aspects of COM is its concept of an apartment. Apartments are used to model concurrency in COM and do not have analogues in most operating systems or languages. This chapter offers nine concrete guidelines that help developers ensure that their objects operate properly in a multithreaded environment. Aspects of apartments discussed include real-world lock management, common marshaling errors, and life-cycle management.
Security
One of the few areas of COM that is more daunting than apartments is security. Part of this is due to the aversion to security that is inherent in most developers, and part is due to the fairly arcane and incomplete documentation that has plagued the security interfaces of COM. This chapter offers five concrete guidelines that distill the security solution space of COM. Aspects of security discussed include access control, authentication, and authorization.
Transactions
Many pages of print have been dedicated to Microsoft Transaction Server, but precious few of them address the serious issues related to the new transactional programming model implied by MTS. This chapter offers eight concrete pieces of advice that will help make your MTS-based systems more efficient, scalable, and correct. Topics discussed include the importance of interception, activity-based concurrency management, and the dangers of relying on just-in-time activation as a primary mechanism for enhancing scalability.
Acknowledgments
First and foremost, Chris woul