Interesting use of fluid interfaces?
I'm wondering where and when fluid interfaces are a good idea, so I'm looking for examples. So far I have only found 3 useful cases for example. Ruby 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 other good examples that use a fluent interface?
jQuery . :)
StringBuilder: http://msdn.microsoft.com/en-us/library/system.text.stringbuilder(VS.71).aspx Or
RSpec . Example from the main 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
- Ninject: http://www.ninject.org
-
For an example that doesn't come from general purpose libraries, I've created an auto regression set for the tuning wizard. I created a state machine that fills in the values on the wizard page, checks that the values are acceptable, and then proceeds to the next page. The code for each step in the target machine looks like this:
step.Filler () Fill () Check () GoForward (); ...