using internal or protected vs. property accessor

  • Thread starter Thread starter TS
  • Start date Start date
T

TS

what would be the scenario that you would want to declare a variable of a
class in that fashion instead of a public property accessor?
 
I always take the extreme position on this one - always declare fields as private - then provide the appropriate level of property accessor (public, protected or internal). The crucial thing is it allows you to change the implementation without your clients having to change. I'bve been stung a number of times in C++ when I declared a field as protected and then wanted to change it - but it would have broken all the derived classes.

Regards

Richard Blewett - DevelopMentor

nntp://news.microsoft.com/microsoft.public.dotnet.languages.csharp/<[email protected]>

what would be the scenario that you would want to declare a variable of a
class in that fashion instead of a public property accessor?



---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.766 / Virus Database: 513 - Release Date: 17/09/2004



[microsoft.public.dotnet.languages.csharp]
 
When you want to allow only code inside of derived classes to touch
the property, you could mark it as protected. This is a good rule of
thumb to follow.
 
The unwritten part of my thought, was, when given a choice between a
protected field and encapsulating the field in a protected property,
favor the protected property.
 
Back
Top