[Exceptional C++ Style] Item 17 - Encapsulation

Adrian Fagg adrianf at evaluategroup.com
Mon Dec 20 07:19:00 EST 2004


> -----Original Message-----
> From: effective-cpp-bounces at accu.org
> [mailto:effective-cpp-bounces at accu.org]On Behalf Of Paul Grenyer

> There's another issue I've been wanting to discuss for a
> while and now seems
> the appropriate time.
>
> At the ACCU conference before last (2003) I was in a
> presentation being
> given by Jon Jagger on a parser he had written. He had some
> public data in
> one of his classes and when I queried him on it he said it
> was const (which
> it was) and therefore it didn't matter if it was public.
>
> I have never been able to make my mind-up whether I agreed or
> not. What do
> people here think?

I think the main problem with this is that although such members constitute
part of the class's interface and in a sense don't break encapsulation, the
fact that C++ has a different syntax for reading data members and functions
leads to them not being substitutable for any future interface.
Potentially a bit annoying for templates as well, I would think.

They could be a special case of the special case though.;-) If you have a
structure that is public across the board yet is also immutable, then why
not?

Three must be a reason why C and hence C++ calls parameterless functions
with (), but it's always eluded me.

Regards,

Adrian

Work: mailto:adrianf at evaluategroup.com
Home: mailto:adrian.fagg at ntlworld.com

Pretty pictures: http://homepage.ntlworld.com/rbyadf/




More information about the Effective-cpp mailing list