On Tue, Dec 7, 2010 at 1:55 PM, Paul M Foster <pa...@quillandmouse.com>wrote:

> Here is an example from their [CodeIgniter] user manual:
>
> $this->db->select('title')->from('mytable')->where('id', $id)->limit(10,
> 20);
>

This is known as a "fluent interface" because it attempts to make your code
read more naturally--i.e. fluently. Each method returns either a new object
or the same object ($this) so it can flow into the next method call. In the
latter case, the initial object stored in $this->db implements all the above
methods. I first saw this in mock object libraries for Java, but it was
invented years earlier.

    $mock = $this->getMock('Calculator');
    $mock->expect('add')->once()->with(3, 5)->willReturn(8);

David

Reply via email to