Re: Private Inheritance and Publice Inheritance
SasQ wrote:
On Mon, 03 Sep 2007 14:14:49 -0400, Daniel T. wrote:
http://www.parashift.com/c++-faq-lite/private-inheritance.html
"(...)
The 'Car has-a Engine' relationship can also be expressed
using private inheritance:
class Car : private Engine
(...)"
WHAT?! o_O
What sense makes the above?
The "has-a" relationshit is evidently a composition.
So? The object is composed of its base class subobjects and data
members. If I want to add an entity to my object, why couldn't
I use inheritance?
If someone think different, let he try to think if
the Car could have more than one engine. I haven't seen
that kind of car, but if we do the same with the plane,
we'll see that it could have more engines than one.
How one could express that with use of [private] inheritance??
Those are different engines, are they not? You have to have
a way to identify engines, no? You can derive different classes
for the "left" and "right" engine (or however else you identify
them), and inherit from those.
It's impossible, ant that's the reason why it should be
done with use of composition.
"Composition" and "private inheritance" are orthogonal concepts.
You cannot set them _against_ each other.
There is other thing wrong in that example.
It assumes that for the Car class's implementation
the Engine is an ancestor. So, from the perspective
of the implementation, Car is-a Engine [WTF?? LOL! :P].
I didn't know that a Car is a special kind-of-an
Engine, even if knowing that fact would be restricted
only for private interface of the Car class.
It's ridiculous!
I think you're (like many others before you) confuse some
OO principles (and their applicability) with C++ language
features that have never been intended to serve as the direct
implementation of those principles. Just like many others you
probably assume C++ an OOP language, which it isn't.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask