Tuesday, July 26, 2005 9:44 PM
dbottjer
Power of Properties
Microsoft Developers are familar with properties. Properties have been part of popular MS development tools such as Visual Basic for several version. The tradition has continued in .NET with Win/Web forms controls. Developers can manipulate text, font color, font size, etc. via properties. Perhaps a lesser known fact is that not all OO languages support properties. Many languages simply support Public Fields. A field is basically a fancy name for a class instance variable. Many languages simply make these fields public instead of private or protected. The danger in this practice is that it violates encapsulation and allows direct access to class data. Using properties we are able to encapsulate our class data which allows for things such as data validation. That is when a property is being set, the data being assigned to the property can be validate. For example, we can make sure that a number or a date falls within a certain range.
Filed under: .NET, C#