martinus
martinus

Reputation: 18023

Interesting uses of fluent interfaces?

I am wondering where and when fluent interfaces are a good idea, so I am looking for examples. So far I have found only 3 useful cases, e.g. Ruby's collections, like

unique_words = File.read("words.txt").downcase.split.sort.uniq.length

and Fest (Java) for unit testing:

assertThat(yoda).isInstanceOf(Jedi.class)
    .isEqualTo(foundJedi)
    .isNotEqualTo(foundSith);

and JMock. Do you know of any other good examples that use a fluent interface?

Upvotes: 1

Views: 491

Answers (4)

outinsun
outinsun

Reputation: 51

  1. Ninject: http://www.ninject.org
  2. For an example that doesn't come from general-purpose libraries, I built an automated regression suite for a configuration wizard. I created a state machine that fills in values on a wizard page, verifies those values are acceptable, then moves on to the next page. The code for each step in the state machine looks like:

    step.Filler().Fill().Verify().GoForward();

Upvotes: 0

AShelly
AShelly

Reputation: 35580

RSpec. Example from the home page:

# bowling_spec.rb
require 'bowling'

describe Bowling do
  before(:each) do
    @bowling = Bowling.new
  end

  it "should score 0 for gutter game" do
    20.times { @bowling.hit(0) }
    @bowling.score.should == 0
  end
end

Upvotes: 0

cletus
cletus

Reputation: 625267

jQuery. :)

Upvotes: 3

Related Questions