Reputation: 18023
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
Reputation: 51
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
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
Reputation: 26632
StringBuilder: http://msdn.microsoft.com/en-us/library/system.text.stringbuilder(VS.71).aspx Or
Upvotes: 1