Data encapsulation, data hiding:
Prevent direct manipulation of data elements. Avoid programming errors related to changing a data value incorrectly or at the wrong time.Example: Protecting list integrity in a multi-threaded program; e.g., transparently apply a lock or a critical section around code that manipulates the list.
Data validation, data value enforcement:
It’s a way for you to make your object self-correcting. Examples: Forcibly “pin” a data value so that it is guaranteed to be within a certain range of valid values. For instance, ensuring that a “percentage” variable will be between 0 and 100, inclusive. Make sure that a ZIP Code is exactly five or nine digits.
Transparent data manipulation:
The data itself might be stored in a form that is inconvenient for other parts of the program to use. The property logic does a conversion transparently.
Examples: Encrypt a password, Social Security Number, or other sensitive data when stored but have the clear-text value at hand when used in the program. Provide normalized handling for database NULL values. Transparently “escape” and “unescape” text that is to be displayed in an HTML page or used in an SQL query.
Data source transparency:
The programmer (and the rest of the system) does not need to know exactly how or from where the data was obtained. He just needs the value.
Example: The value is obtained through a COM-object method that might, in turn, access a database hosted on a remote system. But it looks like a local memory variable in the program code.
Invoke a function call to get or set the data by using simple assignment semantics. Hide the “dirty” low-level implementation. This is possibly the most commonly-cited value of properties.