Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are there any Fluent interfaces? [closed]

I have read about Fluent APIs, where code can be made to read like English, but I can't seem to find any examples of them, as I would like to find out whether they are a reasonable way to make an easy to use interface to a system by non full time programmers. Does anyone have any examples of a fluent interface?

like image 582
yazz.com Avatar asked Dec 28 '22 23:12

yazz.com


1 Answers

Couple of examples below in C#. Used by non-programmers? Well, decide for yourself, I'd say probably not - they're designed for coders and you need to know the syntax. But then this is C#, there are better examples in Ruby and other languages with much more readable, english-like syntax.

You'd might want to also look at external DSLs (domain specific languages). (Fluent APIs are considered internal DSLs).

NUnit:

Assert.That(result, Is.EqualTo(10));

Ninject:

Bind<IDataAccess>()
                .To<Db4oDataAccess>()
                .WithConstructorArgument("fileName", "dbFile.db");

Rhino Mocks:

repository.Expect(x => x.LoadUserList()).Return(users);

Here's some Ruby from RSpec:

@account.balance.should eql(Money.new(0, :dollars))

However, bear in mind that these examples are aimed at programmers, it is possible to get much more human-readable code if non-programmers are the target audience, especially with Ruby and the like.

like image 179
Grant Crofton Avatar answered May 10 '23 16:05

Grant Crofton