[comp.lang.c++] Generating public parts from private parts

shap@polya.Stanford.EDU (Jonathan S. Shapiro) (10/05/88)

Sorry about changeing the title, but my machine went to lunch when I
tried to followup.

Someone mad the absurd assertion that the public part of a class could
be generated from the private part.

Not only is this not true in C++; it is not true in Ada, Modula-2, or
any other language he said it was true in.

The issue of data hiding in C++ is this: The language is interested in
providing an abstraction for compilation without giving up
performance. The fact that this has unfortunate header dependencies is
considered less important.

There are two good reasons *not* to make the privaate part pointed-to
from the standpoint of language design:

1. It adds tremendous cost. Private members in practice tend to be
private because they are per-object state. As such, the object tends
to make heavy use of them, so the indirection cost is very
significant.

2. When the size of private/protected components is unknown, the
implementation of inheritance, especially multiple inheritance,
becomes significantly more difficult.

From the standpoint of customer environment, there are two
compatibility concerns that *compel* making the private stuff part of
the class:

1. C++ was designed to be C-linkable. Changing the structure model
would have broken this.

2. C++ was designed to be implementable on *existing* technology in
the interest of portability and speed of propagation.  A library
mechanism could not be assumed, which certainly precludes this sort of
separation - at least if one is concerned with consistency.

Jon