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
4
votes
2 answers

C# Creating a Fluent API for chaining methods

In C#, we can use Func<> and Action<> types to store what are essentially managed pointers to methods. However, in my experience, they need to be explicitly typed when defined: Func someFunc = myObject.MyMethod; I am trying to design a fluent…
Haus
  • 1,492
  • 7
  • 23
4
votes
1 answer

EF 4.1 RC: Weird Cascade Delete

I have to admit, the features of EF 4.1 RC Codefirst, DataAnnotations and FluentAPI are still overwhelming to me. Sometimes I really don't know what I am doing ;-) Please see the following POCOs: public class Country { [Key] public Guid ID {…
4
votes
1 answer

How do I get a delete trigger working using fluent API in EF CodeFirst CTP5?

I am having trouble getting referential integrity dialled down enough to allow my delete trigger to fire. I have a dependent entity with three FKs. I want it to be deleted when any of the principal entities is deleted. For principal entities Role…
4
votes
1 answer

Castle Windsor: So what DOES ActAs do?

I noticed that the castle windsor fluent component registration interface has the rather confusing ActAs() method. Googling around for it the only reference I found was at their wiki here. TODO (Stuff that could be documented) what does ActAs()…
George Mauer
  • 117,483
  • 131
  • 382
  • 612
4
votes
3 answers

How to build a sequence using a fluent interface?

I'm trying to using a fluent interface to build a collection, similar to this (simplified) example: var a = StartWith(1).Add(2).Add(3).Add(4).ToArray(); /* a = int[] {1,2,3,4}; */ The best solution I can come up with add Add() as: …
James Curran
  • 101,701
  • 37
  • 181
  • 258
4
votes
2 answers

How can I make method chaining fluent in C?

There is an existing C API that looks like this: //data typedef struct {int properties;} Widget; //interface Widget* SetWidth(Widget *const w, int width){ // ... return w; } Widget* SetHeight(Widget *const w, int height){ // ... …
Trevor Hickey
  • 36,288
  • 32
  • 162
  • 271
4
votes
2 answers

C# Fluent API With Dynamic Func<> Construction

I'm fooling around with creating a small SQL library with a fluent API and want to do something like this: var person = connection.GetOne("select * from [Person] where [Id] = 1") .WithMany("select * from [Pet]…
Craig Koster
  • 496
  • 5
  • 15
4
votes
3 answers

Is jQuery method chaining an example of fluent programming?

I'm somewhat new to JavaScript/jQuery, but when I saw examples of method chaining it struck me as instantly familiar. Other interfaces like LINQ do something similar where the return type of a set of methods is the same as the type they operate on…
James Cadd
  • 12,136
  • 30
  • 85
  • 134
4
votes
1 answer

New Styles in C#

Fluent APIs are very common these days. Lately, I'm finding them in almost every system I work with. Mostly, they enhance readability but sometimes they lock me in to inflexible specifications, making understanding the runtime behavior of the…
Andrew Matthews
  • 3,006
  • 2
  • 29
  • 42
4
votes
1 answer

Fluent interface with inheritance in Delphi

I have following fluent interface declaration and class that implements that interface: type IDocWriter = interface ['{8CB5799A-14B1-4287-92FD-41561B237560}'] function Open: IDocWriter; function Close: IDocWriter; function…
Dalija Prasnikar
  • 27,212
  • 44
  • 82
  • 159
4
votes
4 answers

Why use a Fluent Interface?

When comparing to classic properties, what's the big gain of using it ? I know the repeating of the instance name is gone, but that's all ? public class PropClass { public Object1 object1 { get; set; } public Object2 object2 { get; set;…
user137348
  • 10,166
  • 18
  • 69
  • 89
4
votes
1 answer

How can I build an interface hierarchy for my fluent API?

I'm working on a fluent API and trying to take advantage of Java's generic methods to offer an elegant API that handles type conversions for my users. I'm running into some trouble getting it working though, due to type erasure. Here's a simplified…
Greg
  • 10,360
  • 6
  • 44
  • 67
4
votes
3 answers

Proxy Authentication With Fluent API Request?

I am currently using a Get Request with proxy information: String result1 = Request.Get("_http://somehost/") .version(HttpVersion.HTTP_1_1) .connectTimeout(1000) .socketTimeout(1000) .viaProxy(new HttpHost("myproxy",…
4
votes
3 answers

Mapping 2 tables to single entity in Entity Framework

I hope you can help me. I have 2 tables in the db: Bill and BillItem. These tables are configured with one to one relation in the db where bill is the principle table while BillItem is the dependent one The structure of table Bill : Int BillId…
4
votes
1 answer

EF Code First: Primary Key same as Foreign Key

I have two classes public class Product { public Guid Id { get; set; } public string ProductDetails { get; set; } } public class SpecialProductDetails { public Guid Product_Id { get; set; } // PK and FK to Product class public…
Catalin
  • 11,503
  • 19
  • 74
  • 147