[Exceptional C++ Style] Item 17 - Encapsulation

Paul Grenyer paul at paulgrenyer.co.uk
Mon Dec 20 05:32:36 EST 2004


Hi All

Daire, thank you for another excellent summary! It will go up on the site a
little later on.

> The author says that the most important thing to get right is the class
> interface - everything else can be fixed. Poor interfaces may be
impossible
> to fix once in use.

...and here in often lies the problem in my experience.

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?

The immediate reason why not that comes to mind is that which is discussed
in the item about not being able to modify the class to do something like
count the number of times the data is accessed without changing the
interface. So, my thinking is that even constant data shouldn't be public.

I imagine (and correct me if I'm wrong) that this item is unlikely to cause
much controversy and that constant public data might provide a good
discussion.

Regards
Paul

Paul Grenyer
email: paul at paulgrenyer.co.uk
web: http://www.paulgrenyer.co.uk
articles: http://www.paulgrenyer.dyndns.org/articles/

Darrell "Dimebag" Abbott will be sorely missed.




More information about the Effective-cpp mailing list