Sudheer Satyanarayana wrote:
>
>
> It is next to impossible to write all the benefits of using OOP in this
> email. You should read books about OOP to learn more about it.
>
> The sample you snippet posted appears to demonstrate how to encapsulate
> database access in your models.
>
>
And don't forget if you want to shorten the code (at the same time as
keeping the benefits of OOP), you could always use overloading methods for
accessors and mutators (wow I learned some big fancy words) as such:
class member {
protected $_data = array(
'field_a' => null,
'field_b' => null,
'field_c' => null
);
/* Accessor */
public function __get($name) { return $this->_data[$name]; }
/* Mutator */
public function __set($name,$value) { $this->_data[$name] = $value; }
}
Of course the setter/getter methods can have logic to them (ie.
array_key_exists), in order to validate that the property you are accessing
exists, is valid, etc.
PHPScriptor: With the use of arrays over objects, you lose the ability to
encapsulate the behaviors within the object, as well as protecting the
properties from modification. If you want to change a value of an array
key, you just set it. Any validation has to be repeated for every function
that accesses the array in order to protect the data from being 'mutated'.
Whereas if you handle it in OOP terminology, you can easily protect your
object state from modification through the object itself. Therefore the
object can define who/what/how the object state can be modified. In other
words, arrays do have their place for the simplest of usages, but OOP has a
great deal of advantages in real world development.
Peace
Aaron
--
View this message in context:
http://www.nabble.com/Object-oriented-programming-with-Zend-tp25625247p25654328.html
Sent from the Zend Framework mailing list archive at Nabble.com.