Re: Composition versus Implementation Inheritance
chsalvia@gmail.com wrote:
"Daniel T." <danie...@earthlink.net> wrote:
Basically, it seems you're saying that the possible danger of
declaring a class outside of its appropriate context is not a
sufficient reason by itself to use private inheritance.
No, I'm saying that even if you do declare all class' constructors
protected, the class can still be used outside of its appropriate
context.
I was just thinking that in a case where you have class A, B and C,
where B and C use A internally, and declaring A anywhere else would
be senseless or possibly dangerous, it would be beneficial to
somehow restrict developers from instantiating A, *unless* they are
specifically trying to extend A, in which case they're probably well
aware of how A works.
If a library vendor has developed A for internal use (i.e., they have
not documented it,) it is "senseless or possibly dangerous" for anybody
other than them to use it, *even* if they are specifically trying to
extend it. Being "well aware of how A works" is irrelevant because the
vendor can make major changes to the way A works between versions (it is
not a published interface.)
<http://www.martinfowler.com/ieeeSoftware/published.pdf>
It would probably be nice to have some form of library level access
privileges, however C++ doesn't have anything like that and I think
abusing class level privileges in an attempt to simulate it is
inappropriate.