On 17 Jul 2005 07:09:41 -0700, "Nick Keighley"
<ni******************@hotmail.com> wrote:
[snip]
In order for the derived class to implement its draw() method it needs
to know the size. Protected data seems to be frowned on. So is my only
choice protected get() and set() methods? Or public?
I would implement some virtual "getSize()" function. You never know if
this needs to be extended in the future. Perhaps you will want to take
into consideration some scaling factor for certain derived classes?
Bjarne Stroustrup, in "The C++ Programming Language" (p. 405 of the
3rd edition) states that "declaring data members protected is usually
a design error". Later, he goes on to say that this creates a
"software maintenance problem".
To me, it never became obvious what he meant until I started working
on one of my first fairly large projects. It became painfully obvious
when the member (a pointer) was in the base class, and the derived
class was supposed to initialize it as well as call delete on this
pointer in the derived destructor. Wasn't well documented, either. Now
consider having to check 30 or 40 different projects to make sure that
this was done correctly, and you'll see what I mean.
For invariants implemeneted as const members, though, I think there is
no danger of declaring them protected. In practice, though, I think
one finds very few instances of this compared to very many instances
of the abuse of protected members.
--
Bob Hairgrove
No**********@Home.com