CSharpFeeds - All your C# feeds in one place.

Sponsors

Thursday, April 24, 2008

Great fluent interface sample: the fluent repeater

by Fabrice Marguerie via Fabrice's weblog on 4/24/2008 1:52:00 PM

I'm not that much a fan of fluent interfaces, but in some cases they are well fit.

A great example is the fluent repeater created by Adrian Aisemberg. It's also a good example if you don't know what a fluent interface is.

Here is sample code that uses it:

Repeat.Call<string>(Save).WithParameters("myfile.txt").UntilSucceeds.Start(10);
Repeat.Call(Ping).PauseBetweenCalls(2000).Start(100);

Some more:

Repeat.Call(Open).InBackgroundThread.At(ThreadPriority.Lowest).
        OnSuccessCall(Opened).OnExceptionCall(Failed).Start();

This could be written in the following way using a non fluent interface:

Repeater repeater = new Repeater();
repeater.Method = Open;
repeater.InBackgroundThread = true;
repeater.ThreadPriority = ThreadPriority.Lowest;
repeater.Success += Opened;
repeater.Exception += Failed;
repeater.Start();

Which version do you prefer?

email it!bookmark it!digg it!

Original Post: Great fluent interface sample: the fluent repeater

Subscribe

New Feed

Product Spotlight

Recently Updated Sources

Legal Note

The content of the postings is owned by the respective author. CSharpFeeds is not responsible for the contents of the postings. This site is automatically generated and cannot be reviewed for abusive content. If you find abusive content on CSharpFeeds, please contact us. Designated trademarks and brands are the property of their respective owners. All rights reserved.

Advertise with us