Re: Two questions for help!
From: Dave Townsend (datownsend_at_comcast.net)
Date: 09/25/04
- Next message: Andy: "Re: inline functions"
- Previous message: Dave Townsend: "Re: objects with member references.."
- In reply to: Daniel T.: "Re: Two questions for help!"
- Next in thread: Ioannis Vranos: "Re: Two questions for help!"
- Reply: Ioannis Vranos: "Re: Two questions for help!"
- Reply: David Hilsee: "Re: Two questions for help!"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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.
- Next message: Andy: "Re: inline functions"
- Previous message: Dave Townsend: "Re: objects with member references.."
- In reply to: Daniel T.: "Re: Two questions for help!"
- Next in thread: Ioannis Vranos: "Re: Two questions for help!"
- Reply: Ioannis Vranos: "Re: Two questions for help!"
- Reply: David Hilsee: "Re: Two questions for help!"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|