Re: Two questions for help!

From: Dave Townsend (datownsend_at_comcast.net)
Date: 09/25/04


Date: Fri, 24 Sep 2004 21:31:48 -0700


"Daniel T." <postmaster@earthlink.net> wrote in message
news:postmaster-6B8393.23311024092004@news2.east.earthlink.net...
> "away" <Gusalpine@spambs.com> wrote:
>
> > 1. It is showed in a book that a class has all member variables declared
as
> > protected. What's the reason for doing this?
>
> Making a variable protected ensures that only the class and sub-classes
> can modify the variable. The assumption is that sub-class writers will
> be careful enough.
>
> Personally, I feel that all variables should be declared private.

Can you enumerate why all variables should be private ? I've written
classes a a number
of times where I've made all variables private and had to write numerous
member functions
to allow access to the variables by the derived classes, it didn't seem that
there was much
advantage and a lot of extra code was needed to wrap the data member . It
seems
to me that there are good reasons for making variables protected :-

   1. if the derived classes would access them
   2. modifying these variables does not require side effects.



Relevant Pages

  • Re: Two questions for help!
    ... What's the reason for doing this? ... Making a variable protected ensures that only the class and sub-classes ... can modify the variable. ... I feel that all variables should be declared private. ...
    (comp.lang.cpp)
  • Re: How should this sentence be interpreted
    ... procedure will modify it." ... There are immutable classes. ... the passing mechanism is more efficient because of passing only the refence. ... A structure is more complicated to implement correctly, so stick to use classes unless there is a good reason to use a structure. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: [PATCH] THE LINUX/I386 BOOT PROTOCOL - Breaking the 256 limit (ping)
    ... maybe (some BIOSes leave us ... Or modify the whole code to use 16 bits? ... No reason. ... Dell Linux Solutions linux.dell.com & www.dell.com/linux ...
    (Linux-Kernel)
  • Re: summing fields
    ... THe reason I am doing this is ... If you insist on keeping this decidedly un-normal data structure, ... modify your formula/expression to use the Nzfunction to convert nulls to ... another state, you'll have to modify any/all formulas, your table structure, ...
    (microsoft.public.access.forms)
  • Re: doubt related to string pointers.
    ... >What is the reason for that? ... It is an implementation detail whether there are one or two strings ... is perfectly legal to modify str as often as you want. ...
    (comp.lang.c)