10-01-2007, 11:24 AM
|
#3 (permalink)
|
|
The Reckoner
Join Date: Sep 2007
Posts: 438
Thanks: 22
|
Readability and reduction of code repeation. Consider the following example I use in my library:
PHP Code:
$aMembers = $this->m_pMembers ->join('jobs') ->join('orders') ->fetchAll($szFields, $szConditions);
The same code could be written like this, without method chaining:
PHP Code:
$this->m_pMembers->join('jobs'); $this->m_pMembers->join('orders'); $aMembers = $this->m_pMembers->fetchAll($szFields, $szConditions);
Admitidly, we've actually added an extra line of code using method chiaining, but we've reduced the amount of code written, removed duplicate code and made it much easier to read. It's all a matter of preference in all honesty, there is no clear cut advantage (that I personally know of, can anyone give me one?) of using method chaining, it's simply a OOP feature that can be used to help improve your code.
|
|
|
|