|
-
Dec 29th, 2008, 01:14 PM
#1
Thread Starter
Fanatic Member
Protected fields
With reference to the following link to MSDN titled 'Do not declare visible instance fields'...
http://msdn.microsoft.com/en-us/libr...41(VS.80).aspx
Externally visible refers to public, protected, and protected internal (Public, Protected, and Protected Friend in Visual Basic) accessibility levels.
Protected fields are also considered visible.
...I am a bit confused as to why fields defined as 'protected' in a class are considered to be externally 'visible'.
As I understand it, if you have an abstract class and a protected field defined within that class, that field can only be accessed by the containing class, and any classes derived from it. I agree that it is visible from classes other than the one it is defined in, but only derived classes. Isn't that the point of 'protected'?
The article suggests defining the field as 'private', and accessing it via a protected property.
This seems like an unnecessary step to me, but perhaps I am missing something. (Highly likely.)
Thoughts?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|