Path: utzoo!mnetor!tmsoft!torsqnt!lethe!yunexus!ists!helios.physics.utoronto.ca!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!brunix!sdm From: sdm@cs.brown.edu (Scott Meyers) Newsgroups: comp.lang.c++ Subject: Re: Nonvirtual base classes in MI Message-ID: <64173@brunix.UUCP> Date: 8 Feb 91 15:39:08 GMT References: <1174@zinn.MV.COM> Sender: news@brunix.UUCP Reply-To: sdm@cs.brown.edu (Scott Meyers) Organization: Brown University Department of Computer Science Lines: 35 In article <1174@zinn.MV.COM> mjv@objects.mv.com (Michael J. Vilot) writes: | I agree with Keith, and with Tom Cargill, that private base classes can be | transformed into class members. There may be some minor performance | differences between the two, but I suspect on average it's a wash. No no no. You lose virtual functions when you turn inheritance into member containment. There is a conceptual distinction between the following: A has a member B ==> A "has a" B (or A "contains a" B) A publicly inherits from B ==> A "is a" B A privately inherits from B ==> A "is implemented in terms of a" B Private inheritance is a convenient way to share code when there is no other conceptual relationship between two classes. I usually call this "code stealing." When stealing the code in another class, you often have to do some class specific stuff; this is where virtual functions come in. The member functions in the (private) base class can call virtual functions to do the customization. This won't work with member objects, because they have no way of knowing what they're a part of. | Each decision represents a particular design choice. In my case, I used | private derivation to express the difference between the abstract class and the | ``concrete'' classes derived from it -- the derived classes mix in their | representation. Making the representation class a private base separates it | from the other members of the class, and highlights the design decision. Right. Each derived class object "is an" abstract class object, hence public inheritance in that case. However, each derived class object "is implemented in terms of" an representation object, hence private inheritance. Scott ------------------------------------------------------------------------------- What do you say to a convicted felon in Providence? "Hello, Mr. Mayor."