View Single Post
Old 10-01-2007, 12:24 PM   #3 (permalink)
Karl
The Reckoner
Advanced Programmer Top Contributor 
 
Karl's Avatar
 
Join Date: Sep 2007
Posts: 438
Thanks: 22
Karl is on a distinguished road
Default

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.
Karl is offline  
Reply With Quote
The Following 2 Users Say Thank You to Karl For This Useful Post:
codefreek (10-28-2008), Runar (11-12-2008)