[Exceptional C++ Style] Item 14: Order, Order!
Kevlin Henney
kevlin at curbralan.com
Sun Dec 12 12:05:08 EST 2004
In message
<20041210091455.HFZU20377.aamta02-winn.mailhost.ntl.com@[62.253.162.95]>,
Ric Parkin <ric.parkin at ntlworld.com> writes
>
>From: Raj Jammalamadaka <cppuser2002 at yahoo.com>
>
>> Except for friendship, inheritance is the strongest
>> relationship that can be expressed in C++ and should
>> be used only when it’s necessary.
>
>Here's a slightly interesting one - is friendship stronger than inheritance?
No. Hasn't been in the past and isn't now.
>In one way, yes: a friend has full access to a class, whereas a derived
>class can't see the base's private members.
Intimate, but specific and local. Friendship is constrained, derived
classes are not.
>In another way, no: to the client, the friend is just another
>class/method, whereas the derived class IsA base class, with all the
>implicit conversions implied.
Inheritance is a significantly stronger coupling relationship than
friendship. At least Herb is consistent in getting the ranking slightly
wrong, as it this ranking is mentioned in other books. Just examine the
consequence of the two relationships on a real (or indeed, imagined)
source base and see what happens. The effect of ill-considered
inheritance is far more pronounced than ill-considered friendship, and
likewise the effect of any changes.
Kevlin
--
____________________________________________________________
Kevlin Henney phone: +44 117 942 2990
mailto:kevlin at curbralan.com mobile: +44 7801 073 508
http://www.curbralan.com fax: +44 870 052 2289
Curbralan: Consultancy + Training + Development + Review
____________________________________________________________
More information about the Effective-cpp
mailing list