The Artima Developer Community
Interviews | Discuss | Print | Email | First Page | Previous | Next
Sponsored Link

Multiple Inheritance and Interfaces
A Conversation with Scott Meyers, Part I
by Bill Venners
December 16, 2002

Page 1 of 4  >>

Advertisement

Summary
Scott Meyers, C++ expert and author of numerous books including Effective C++, talks with Bill Venners about multiple inheritance and interfaces.

Scott Meyers is one of the world's foremost experts on C++ software development. He wrote the best-selling Effective C++ series (Effective C++, More Effective C++, and Effective STL), wrote and designed the Effective C++ CD, is consulting editor for Addison Wesley's Effective Software Development Series, and is a member of the advisory board for Software Development magazine. A programmer since 1972, he holds an M.S. in Computer Science from Stanford University and a Ph.D. from Brown University.

In this four-part interview, which will be published in weekly installments, Meyers gives his views on many topics of object-oriented design, including the use of multiple inheritance in light of Java's interface, designing minimal and complete interfaces, public data members and contracts, and the utility of const. In this initial installment, Meyers indicates how his view of multiple inheritance has changed with time, describes the C++ community's take on Java's interface, and points out a schism of focus between the C++ and other prominent development communities.

Using Multiple Inheritance Judiciously

Bill Venners: Your book Effective C++ was the first book on object-oriented programming that I bought, and I picked up a lot of fundamentals from it. For example, I had never heard of ISA (as in an ArrayList IS A List) before reading your book. Your guideline, "Make sure public inheritance models ISA" was my first introduction to that idea. I probably hadn't even heard that data should be private before reading your book.

I read Effective C++ back in the early 90s, when I was moving from C to C++. Much of my philosophy of object-oriented design originally came from your book, but since then I've changed the way I think about design in some ways. I'm curious how your ideas of object-oriented design may have changed or evolved since you wrote Effective C++. My first question for you involves multiple inheritance and interfaces.

Any time you used the word "judiciously" in an Effective C++ guideline it really scared me away. For example, you said, "Use private inheritance judiciously." I didn't just use private inheritance judiciously, I never used it at all. You said, "Use multiple inheritance judiciously." In five years of C++ programming, I never once used multiple inheritance.

My attitude about multiple inheritance in C++ didn't come only from your book. Most of my friends who were programming in C++ shared that attitude. The way we thought about multiple inheritance was that given two full blown classes, each of which could be instantiated, you create a third full blown class that inherits from the other two. That class structure, which is what we thought of when we thought of multiple inheritance, has all the problems you describe in Effective C++. I wasn't determined to avoid multiple inheritance in C++ at all costs, but in five years I never encountered a situation in which I felt inheriting from multiple base classes made sense in my designs.

When I moved from C++ to Java in early 1996, however, I encountered Java's interface. I quickly learned the mechanics of Java's interface—I understood how it worked—but I didn't know how to design with it. Here was multiple inheritance again, but not the full blown kind of multiple inheritance I was used to in C++. With Java's interface construct, I could multiply inherit interface but not implementation. In the C++ terminology you used in Effective C++, Java only let me multiply inherit from abstract base classes (ABCs) that had no data members and only pure virtual functions.

Page 1 of 4  >>

Interviews | Discuss | Print | Email | First Page | Previous | Next

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2014 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us