More on Accessors
Below are some other examples of how accessors can be used to good effect.
Calculated results are possible, instead of simply returning the static data from the array.
One other useful function accessors can play is updating cached values.
Since all changes must go through the
Calculated results are possible, instead of simply returning the static data from the array.
One other useful function accessors can play is updating cached values.
Since all changes must go through the
setX()
method, that is a perfect place to reset some cached value which is dependent on X.
Our class hierarchy is evolving as well:
- Internal manipulation of the
$_data
variable has been replaced by the private methods_getData()
and_setData()
. - These generic methods have been moved to an abstract superclass of the
User
class calledRecord
.
The Record class handles the details of accessing the
$_data
array, calling validation methods before properties are modified, and posting change notifications to Records, as well as to a central ObjectStore instance.