Re: Too much encapsulation?



On Fri, 15 Jun 2007 13:06:01 +1200, Ian Collins wrote:
copx wrote:
If the type of "object" is incomplete, you could not write object->colour or
something like that, because accessing data of incomplete type is not
possible.
[...]
So do you consider that proper C style?

Yes, and it's a very common idiom (have you ever manipulated a FILE
object?).

Unfortunately you frequently see generous 'un-encapsulation' in C
code. Structs are defined completely in the header file but only
pointers to functions are used in the function declarations (other
'private' elements (defines, macros, enums) are also unnecessarily
placed into the header). Many programmers seem to be unaware of gratis
encapsulation.

Personally, I am not sure what to think of this. It seems to scream "Why do
you not use C++ already?!".

Nothing to do with C++, unless you are using a similar idiom with opaque
types, C++ classes lay their innards bare for all to see.

but not for all to access. Encapsulation is independent of language
and paradigm (it's not an original OO feature).



--
Roland Pibinger
"The best software is simple, elegant, and full of drama" - Grady Booch
.