Data Protection in PHP

Nov 12, 2010 Author: City Hall

The reason to use classes is that they provide data protection; that is, classes prevent a programmer from making logic errors in dealing with complex data structures.

Using a class’s member functions to modify its member variables protects a class’s data. By doing this, you are guaranteed that all of the changes necessary to perform a desired task are executed every time you want to perform the task.

For example, one desired function of a bank account class might be to keep a record for each transaction made with the account. However, if a programmer simply modifies the account’s Balance member, he will probably neglect to add an entry to the account history.

Good object-oriented programming practices dictate that a programmer should use functions to access and modify the data within an object. Thus, the programmer will have a smaller chance of making a mistake.

views 4908
  1. Add New Comment