The Artima Developer Community
Sponsored Link

Meaningful Programming
A Conversation with Scott Meyers, Part III
by Bill Venners
December 30, 2002

<<  Page 2 of 3  >>



Bill Venners: In Effective C++, you state that the three common relationships between classes are IS-A, HAS-A, and IS-IMPLEMENTED- IN-TERMS-OF. IS-A really helped me understand inheritance. HAS-A, as in a Person HAS A Name, didn't really help me much to understand layering—what I usually call composition. You're other layering relationship, IS-IMPLEMENTED-IN-TERMS-OF, although a mouthful, made sense to me. Is that still how you describe the different ways to related classes? Has anything changed in the last 10 years in how you would describe the basic class relationships?

Scott Meyers: In terms of the vocabulary I introduce in the book, nothing has changed. In fact, I didn't change any vocabulary in the second edition of Effective C++. I still think of those terms as the three fundamental relationships between classes.

Bill Venners: Please differentiate HAS-A and IS- IMPLEMENTED-IN-TERMS-OF.

Scott Meyers: When you write software, you deal with two worlds. You deal with the world you want to model, the outside world. You also deal with a world that exists only inside the software, which involves just getting the code to work. HAS-A corresponds to something in the real world. A Car HAS Wheels or a Person HAS Friends. HAS-A corresponds to the application domain. IS-IMPLEMENTED-IN-TERMS-OF never exists in the real world; it is part of the implementation domain. So you couldn't say a Car IS-IMPLEMENTED-IN-TERMS-OF Wheels. A Car HAS Wheels. But you could say the ParkingLot IS-IMPLEMENTED-IN-TERMS-OF a List. There's no List in the real world. The List only exists inside the software. So HAS-A is a relationship between classes that exists in the application domain. IS-IMPLEMENTED-IN-TERMS-OF is a relationship between classes that exists in the implementation domain.

Bill Venners: That's great. That clarifies it for me.

Scott Meyers: It took me a few years to figure that out myself, actually.

<<  Page 2 of 3  >>

Sponsored Links

Copyright © 1996-2018 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use