Easy one: Use Properties instead of data members.
Reasons why:
- .NET supports properties for data binding code classes, but does not support data members.
- Validations can be used within the property. Validations will then be coupled with the objects themselves instead of being implemented everywhere the object is used, simplifying code maintenance.
- Multithreading can be added easier just by adding the synchronization to the get and set methods.
- Greater flexibility on the visibility of different functions of your property. For example, the get method can be public but the get method is protected and can only be called within the object hierarchy.
No comments:
Post a Comment