ebook img

Programming With Direct To SOM C++ PDF

468 Pages·1997·226.2 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Programming With Direct To SOM C++

Programming with DirectToSOM·· c ++ • Covers SOM, DSOM, and CORBA Object Services • Includes Release-to-Release Binary Compatibility (RRBC) Support • Examples of Interlanguage Object Sharing JENNIFER HAMILTON Programming with DirectToSOM™ C+ + JENNIFER HAMILTON Wiley Computer Publishing John Wiley & Sons, Inc. New York • Chichester • Brisbane • Toronto • Singapore • Weinheim Publisher: Katherine Schowalter Editor: Theresa Hudson Managing Editor: Micheline Frederick Electronic Products, Associate Editor: Mike Green Text Design & Composition: North Market Street Graphics Designations used by companies to distinguish their products are often claimed as trademarks. In all instances where John Wiley & Sons, Inc., is aware of a claim, the product names appear in initial capital or ALL CAPITAL LETTERS. Readers, however, should contact the appropriate companies for more complete information regarding trademarks and registration. This text is printed on acid-free paper. Copyright © 1997 by John Wiley & Sons, Inc. All rights reserved. Published simultaneously in Canada. This publication is designed to provide accurate and authoritative information in regard to the subject matter covered. It is sold with the understanding that the pub lisher is not engaged in rendering legal, accounting, or other professional service. If legal advice or other expert assistance is required, the services of a competent pro fessional person should be sought. The opinions expressed in this book are those of the author and do not represent those of her employer. Reproduction or translation of any part of this work beyond that permitted by sec tion 107 or 108 of the 1976 United States Copyright Act without the permission of the copyright owner is unlawful. Requests for permission or further information should be addressed to the Permissions Department, John Wiley & Sons, Inc. Library of Congress Cataloging-in-Publication Data: Hamilton, Jennifer, 1965- Programming with DirectToSOM C++ I Jennifer Hamilton. p. cm. Includes index. ISBN 0-471-16004-0 (pbk. : acid-free paper) 1. Object-oriented programming (Computer science) 2. C++ (Computer program language) I. Title. QA76.64.H356 1996 005.13'3-dc20 96-34366 CIP Printed in the United States of America 10 9 8 7 6 5 4 3 2 1 To my parents, Mary and Stan, who taught me to work hard and enjoy learning. + IV About the Author About the Author Jennifer Hamilton holds a BSc Honours in Computer Science from the University of Victoria, BC, and is currently completing a Computer Science MMath with the University of Waterloo. She has worked in compiler devel opment since joining the IBM Toronto Laboratory in 1987. Jennifer is the author of two books and numerous articles on programming language related topics, and is currently responsible for developing the DirectToSOM C++ support for IBM's future-generation C++ language product. Acknowledgments Many people have contributed to this book, both directly and indirectly. Mark Mendell and Brian Thomson endured a million questions, and were great to work with, as I struggled to learn about SOM, DirectToSOM C++, and our VisualAge C++ compiler all at once. Liane Acker was extremely helpful in answering all my questions about DSOM. The DSOM chapter would not be what it is without her advice and technical expertise. Jacob Slonim encouraged me to research and write about SOM, which led in part to this book. John Ferreira got me started with DirectToSOM C++ develop ment and encouraged me to write about it. I would also like to thank and acknowledge the many people con tributed to this book by reviewing the material and providing valuable com ments and suggestions; in particular, Mark Mendell. Also Liane Acker, Ray Barsness, Scott Danforth, John Ferreira, Robert Klarer, John O'Keefe, Catherine Lung, Stephen Miller, Ashvin Radiya, Judd Rogers, Pete Schommer, Roger Sessions, Kevin Sutter, Nick Tindall, Brian Thomson, and Wai Ming Wong. Portions of the material in this book originally appeared in the C+ + Report magazine and the proceedings of the 2nd USENIX Conference on Object-Oriented Technologies and Systems, and has been reproduced with the permission of the respective publishers. w F 0 R E 0 R D Object-oriented programmers dream of a world with vast collections of reusable components, transforming our industry from its current ''build from scratch" development paradigm to one where programmers simply "assemble" components into applications. We expect that the ability to build on the work of others will tremendously improve our ability to construct new applications that have far greater functionality and are of much higher quality than those we could have built from scratch. However, despite the great strides we have made in object tech nology, especially in languages and tools, we are still limited by our technology for packaging objects into binary libraries that can be used across applications and across programming lan guages. Microsoft has developed a limited solution to the problem called component object model (COM) which has become the cornerstone of its current software strategy. But, even before COM was developed, IBM, with the backing of its more visionary executives (especially Vice President of Software Technical Strategy Larry Loucks), began work on a much more ambitious solution to the object packaging problem, the System Object Model (SOM). SOM first shipped in OS/2 2.0 in March 1992. SOM, like COM, provides a way to develop libraries of reusable binary object imple mentations. Unlike COM, SOM fully supports object-oriented technology. SOM provides a common object run time that can be tightly integrated into many programming languages and development tools and that allows objects to be shared across different languages or different implementations of the same language. SOM also supports release-to-release binary compatibility, or RRBC. RRBC means that an object library provider can evolve his or her library in almost any way that would not require a using-application's source to be recoded without requiring the application to be recompiled. For example, one can change the size of objects, add additional methods, change the implementation of methods, or even add new object classes into a class hierarchy without breaking binary compatibility with existing compiled applications that dynamically link to the object's implementation. SOM is a key component in IBM, Apple, and other companies' software strategies. It is available now (or will be very soon) on almost all IBM systems, the Apple Macintosh, Microsoft Windows 95, Microsoft Windows NT, and Tandem's Guardian system. SOM is also the object foundation for the industry-wide effort of OpenDoc. For several years, SOM has supported the Object Management Group's CORBA standard for distributed comput ing, which allow methods to be called on objects wherever the objects are located. In addi- v vi + Foreword tion, IBM has recently developed a way for SOM objects to appear as COM and/or OLE objects. Now, developers using COM/OLE-based tools (such as Visual Basic) can directly leverage libraries of SOM objects without even being aware that SOM is involved. This capability includes the ability to access remote SOM objects. This support is expected to ship later this year for Windows 3.1, Windows 95, and Windows NT. SOM support exists for a number of programming languages including C, C++, Smalltalk, and COBOL, with Java support coming soon. You can get late-breaking news about SOM, interact with other SOM users, and get free downloads of SOM technology from the SOM Web page at: http://www.software.ibm.com/objects/somobjects. This book covers one of the most exciting recent developments in SOM technology-the ability to directly and seamlessly leverage SOM within a C++ development environment. This technology is called DirectToSOM (DTS) C++. It allows a programmer to "just program in C++" and yet implement, use, and subclass SOM-based objects. DTS C++ is the result of major effort between IBM and the Metaware Corporation to develop a complete mapping of the full set of C++ language features to the SOM run time. This book is a thorough intro duction to this exciting technology, providing numerous practical examples of its use. With the delivery of the IBM VisualAge DTS C++ development environment, C++ developers can leverage their C++ skills in a highly productive integrated development environment to pro duce robust, reusable, and language-neutral binary libraries of object definitions. DTS C++ allows you to fully exploit the capabilities of SOM and C++. Even if you are concerned only with in-house C++ development, you will find that the release-to-release binary compatibil ity you get with DTS C++ gives an enormous productivity boost to team development because it greatly reduces the need for massive rebuilds of your software every time one of your base classes changes. IBM Visual Age C++ with DTS support is available now for Windows NT, Windows 95, OS/2, AIX, and MVS, with more platforms coming soon. Jennifer Hamilton is a member of the VisualAge C++ compiler team responsible for developing the compiler's DTS support. She has drawn upon her unique experience and her access to the rest of the technical team to bring you this book. It contains all of the insight and practical information you need to get started immediately enjoying the benefits of a state-of-the-art C++ development environment combined with all the advanced object tech nology of SOM. It covers the SOM technology and shows you how to take full advantage of SOM, including RRBC, distribution, and cross-language support. Extensive use of code examples will help you get started quickly and the sections on distributed SOM will give you all the practical advice you need to leverage the exciting world of CORBA-based distributed computing. Enjoy. Mike Conner, Ph.D. Mike Conner is a Senior Member of the Technical Staff at IBM and is the creator of SOM. He can be reached at [email protected]. c s 0 N T E N T Preface ix List of Figures xii Chapter 1: Introduction to SOM 1 The Disadvantages of Object-Oriented Programming Languages 1 The System Object Model 4 DirectToSOM C++ 10 Summary 12 Chapter 2: DirectToSOM C++ Overview 15 Defining DirectToSOM C++ Classes 15 Basic Concepts 18 Setup 24 Chapter 3: Release-to-Release Binary Compatibility 35 Supporting RRBC 35 Supported Changes 39 Unsupported Changes 43 A Complete Example 44 RRBC Usage Considerations 50 Chapter 4: Using DirectToSOM C++ 51 DirectToSOM C++ Pragmas 51 Macros Defined for DirectToSOM 80 Compiler Options 80 Chapter 5: Programming Considerations 83 Differences between Native C++ and DirectToSOM C++ 83 Programming Considerations 92 Common Programming Problems 124 Chapter 6: Inside DirectToSOM C++ 133 The SOM Object Model 133 SOM Class Data Structures 140 SOMObject Methods 148 Name Mangling 151 VII + VI 11 Contents Chapter 7: IDL Generation 155 Generating an IDL File 155 Mapping DirectToSOM C++ Classes to IDL 162 Mapping Types from C++ to IDL 174 Other Mappings 181 Generating IDL-Specific Information from C++ 190 Generating DirectToSOM Class Definitions from IDL Definitions 194 The Interface Repository 201 Chapter 8: Distributed SOM 203 DSOM Overview 203 DSOM Programming Considerations 217 Putting It All Together 252 Common DSOM Problems 264 DSOM 2.x 269 Chapter 9: Interlanguage Object Sharing 275 Introduction 275 Smalltalk 276 00 COBOL 278 Style Guidelines for Defining DTS C++ Classes 282 Examples 284 Chapter 10: The SOMObjects Object Services 305 Overview 305 Naming Service 312 Life Cycle Services 324 Object Identity Service 329 Externalization Service 332 Persistence 341 Appendix A: SOMObject Header Files 377 <somapi.h> 3 77 <somcorba.h> 393 <som.hh> 398 <somh.hh> 398 <somobj.hh> 399 <somcls.hh> 404 Appendix B: Persistence SOM 415 Persistent Objects: An Overview 415 The Persistent ID 419 Restoring Persistent Objects 423 Working with Persistent Objects 426 Persistent Message Queue 429 Programming Considerations and Common Problems 439 Migration Considerations for POSSOM 440 References 445 Index 447

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.