Questions tagged [fluent-interface]

Refers to a practice of coding object-oriented APIs with the aim of improving readability of the interface, normally implemented using method chaining. The phrase was first coined by Eric Evans and Martin Fowler.

Martin Fowler's explanation on what he considers to be the proper way to design fluent interfaces can be found at http://www.martinfowler.com/bliki/FluentInterface.html.

Related concepts:

437 questions
5
votes
1 answer

javascript fluent api vs options object

A javascripter I respect talks about how you should avoid large options objects in favor of a fluent api. Why? What are the pros and cons? Avoid large options objects If you component truly only takes a few options, and are unlikely to change after…
Harry
  • 52,711
  • 71
  • 177
  • 261
5
votes
2 answers

Question regarding fluent interface in C#

I have the following class: public class Fluently { public Fluently Is(string lhs) { return this; } public Fluently Does(string lhs) { return this; } public Fluently EqualTo(string rhs) { return this; } public…
Jeff
  • 13,079
  • 23
  • 71
  • 102
5
votes
1 answer

Implementing conditional in a fluent interface

I've been trying to implement a fluent interface for a set of rules in my system. What I am trying to accomplish is this TicketRules .RequireValidation() .When(quartType => quartType == QuartType.Before).TotalMilageIs(64) .When(quartType =>…
Michaël Larouche
  • 837
  • 10
  • 18
5
votes
1 answer

Fluent Interfaces - the number of objects being created

I am in the process of creating some fluent interfaces for some simple validation stuff that I am playing around with. One thing that I have noticed is that I have a lot of different objects being created. For instance given the below…
vdh_ant
  • 12,720
  • 13
  • 66
  • 86
5
votes
1 answer

Mixing fluent and non-fluent interface in one class

I consider fluent interfaces very convenient for many tasks. But I feel uneasy when I end up mixing fluent methods and modifying methods in one class. Just an example (it's a little contrived, please bear with me): Assuming a string utility class,…
peterchen
  • 40,917
  • 20
  • 104
  • 186
5
votes
6 answers

create fluent interface for adding elements to a list

this is what I'm trying to achieve: config.Name("Foo") .Elements(() => { Element.Name("element1").Height(23); Element.Name("element2").Height(31); }) .Foo(23); or…
Omu
  • 69,856
  • 92
  • 277
  • 407
4
votes
5 answers

Dealing with asynchronous control structures (Fluent Interface?)

The initialization code of our Flex application is doing a series of asynchronous calls to check user credentials, load external data, connecting to a JMS topic, etc. Depending on the context the application runs in, some of these calls are not…
4
votes
2 answers

Using Type Inference with fluent interfaces

I have a class /interface hierarchy. On the interface side I have IQuery ISelect (inherits IQuery) IUpdate (inherits IQuery) etc On the class side I have QueryBase (implements IQuery) SelectQuery (implements ISelect) …
Simon Woods
  • 2,223
  • 4
  • 27
  • 34
4
votes
2 answers

C# construction objects with builder

Fluent builder is a well-known pattern to build objects with many properties: Team team = teamBuilder.CreateTeam("Chelsea") .WithNickName("The blues") .WithShirtColor(Color.Blue) .FromTown("London") .PlayingAt("Stamford…
Yippie-Ki-Yay
  • 22,026
  • 26
  • 90
  • 148
4
votes
1 answer

Castle Windsor Fluent Configuration: Is it possible to make a specific lifestyle for a given service without using the concrete implementation?

I have a collection of services that I want to register with Castle Windsor (version 3.0 RC1) using the fluent registration technique. I want all of them except for a particular one to use the transient lifestyle and that one I want to be a…
kmp
  • 10,535
  • 11
  • 75
  • 125
4
votes
1 answer

Entity Framework Code First - One-to-Many with a join/link table

Is it possible to create a One-to-Many relationship with Code First that uses a link/join table between them? public class Foo { public int FooId { get; set; } // ... public int? BarId { get; set; } public virtual Bar Bar { get;…
Dismissile
  • 32,564
  • 38
  • 174
  • 263
4
votes
4 answers

method name for a long method

The good style (Clean Code book) says that a method's name should describe what the method does. So for example if I have a method that verifies an address, stores it in a database, and sends an email, should the name be something such as …
ejaenv
  • 2,117
  • 1
  • 23
  • 28
4
votes
6 answers

refactoring long methods with fluent interfaces

I'd like to know your opinion about using the fluent interface pattern to refactor a long method. http://en.wikipedia.org/wiki/Fluent_interface The fluent pattern is not included in the refactoring books. for example, say you have this long method…
ejaenv
  • 2,117
  • 1
  • 23
  • 28
4
votes
4 answers

EF4.1 - Fluent API - SqlQuery - configuration mappings when calling sproc - Data reader is incompatible with specified entity type

The scenario - legacy application with 10 year history, has always used procedure calls for all data access - needs to be overhauled from a hybrid classic ASP and .NET set of pages. The goal - migrate to .NET 4.0 using EF 4.1 with Fluent API and…
4
votes
5 answers

Are there any Fluent interfaces?

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…
yazz.com
  • 57,320
  • 66
  • 234
  • 385