Fluent Interfaces

company.hires(“law firm”, “criminal law”) was Alef’s example of a fluent interface. If you found it interesting here’s the link to Martin Fowler’s website where he talks about it.

Advertisements

One thought on “Fluent Interfaces

  1. Fluent interfaces are very interesting. They’ve been making their way into PHP as well. The best example I’ve seen so far where a fluent interface would make sense in PHP was in a Database class, where you would get:

    $objQuery->select(‘*’)->from(‘table’)->where(‘active=1’)->orderBy(‘id’)->orderType(‘DESC’);

    Now this is a beautiful way of writing queries, and teh abstraction takes care that the correct query syntax is used for the database system that you’re using.

    Another example, very interesting, from one of the big shots in PHP Mike Naberezny, is the creation of an order:

    $customer->newOrder()
    ->with(6, ‘TAL’)
    ->with(5, ‘HPK’)->skippable()
    ->with(3, ‘LGV’)
    ->priorityRush();

    So yes, fluent interfaces are very interesting.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s