473,327 Members | 1,976 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

protected variables or protected accessors?

Hi

I've got a base class with some protected variables in it,
for use by any sub-classes. This all works fine, but I
have just run the assembly through FxCop and it suggests
making the variables private and adding protected property
accessors to it. I can't see the argument for this. Can
anyone clarify this?

Thanks

John
Nov 22 '05 #1
1 1349
John <an*******@discussions.microsoft.com> wrote:
I've got a base class with some protected variables in it,
for use by any sub-classes. This all works fine, but I
have just run the assembly through FxCop and it suggests
making the variables private and adding protected property
accessors to it. I can't see the argument for this. Can
anyone clarify this?


It's the same as for not making variables public - you get more
flexibility with properties:

o You can change the type of the underlying variable later on
without affecting compatibility (i.e. expose the old property as
well as probably a new one)
o You can have a setter but no getter or vice versa
o You can provide error checking
o You may end up doing something entirely different (e.g. get a
value from the registry, or use a cached version most of the time,
or something like that)

Other than the second one, all of these can be done later on, when
you've got code which depends on the interface you're providing. If
you've just got a variable, you don't get any of that flexibility.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 22 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Scott Brady Drummonds | last post by:
Hi, everyone, I'm still learning Python as I develop a medium-sized project. From my previous experience with C++, I've burnt into my mind the notion of information hiding. I'm having trouble...
1
by: John | last post by:
Hi I've got a base class with some protected variables in it, for use by any sub-classes. This all works fine, but I have just run the assembly through FxCop and it suggests making the...
12
by: xxx | last post by:
I'm having a little trouble understanding why a derivative class cannot access a protected member of the base class in the following code: #include <stdio.h> class CBase { protected: int...
4
by: john smith | last post by:
I was looking at some code that someone had written, and they had a class with all static attributes. Can someone please enlighten me why someone would do that? Doesn't that break the rule of...
25
by: Sahil Malik [MVP] | last post by:
So here's a rather simple question. Say in an ASP.NET application, I wish to share common constants as static variables in global.asax (I know there's web.config bla bla .. but lets just say I...
2
by: dumbo | last post by:
Hello, who gives one more shining solution to me? My application load form "A". The form "A" by means of a push-button load form "B" that in its turn by means of a push-button load form "C". Form...
17
by: yb | last post by:
Hi, Looking for clarification of undefined variables vs. error in JavaScript code. e.g. <script> alert( z ); // this will be an error, i.e. an exception </script>
6
by: MooseMiester | last post by:
This little program just doesn't do what I think it should and I cannot understand what the problem is. I'm running Python 2.4 on Windoze XP. It contains an album class, an album collection...
4
by: Lucas Kanebley Tavares | last post by:
Hey all, I'm working on a project with a layout similar to this: class A { protected: A *next; int i; public: void m(A *a);
0
by: durgadeep | last post by:
I have the following program. It has two classes Species and its sub class NajaNaja. Now I am trying to do this, The following gives me an error. NajaNaja::NajaNaja(int age, int weight, KINDOF...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.