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
3
votes
3 answers

Use Fluent Interface with less Code

How can I reduce these two lines $foo = new Bar(); $baz = $foo->methodOne('param')->methodTwo('param'); to $baz = Bar::methodOne('param')->methodTwo('param'); I´ve seen this specially in Laravel and it´s nice readable Code. But I stuck getting…
Kristo
  • 547
  • 1
  • 7
  • 20
3
votes
2 answers

How to design a Fluent Interface?

I have been trying to design a fluent interface for one of my frameworks and it seems that I can't understand one piece of the puzzle. I understand that I can use interfaces and classes to kind of drive which methods I want to call. However consider…
Afraz Ali
  • 2,672
  • 2
  • 27
  • 47
3
votes
2 answers

How to ensure the sequence of methods in fluent API?

I want to create fluent interface for some of my classes that I am building as part of a framework. I have created the methods and I am able to successfully chain methods. Now I want to ensure that I can handle the improper sequence of method calls.…
Afraz Ali
  • 2,672
  • 2
  • 27
  • 47
3
votes
1 answer

EBNF to fluent interface

I have recently had the need to write a fluent interface for C# that will essentially mirror SQL. Yes, I am aware of LINQ to SQL, but I'm interesting in getting "closer to the metal"--having something that essentially provides nothing more than an…
Eric Smith
  • 5,262
  • 2
  • 33
  • 49
3
votes
1 answer

Fluent Interfaces Implementation

In order to make my code more organized i have decided to use fluent interfaces; However by reading the available tutorials i have found many ways to implement such fluency, among them i found a topic who says that to create Fluent Interface we…
Roman Ratskey
  • 5,101
  • 8
  • 44
  • 67
3
votes
2 answers

How can I simplify the registration of a large set of closed generic versions of the same open generic implementation?

Is there a fluent way of writing the following: var someTypes = GetType() .Assembly .GetTypes() .Where(x => someFilter == true); foreach(var someType in someTypes) { var genericInterface = typeof(IFoo<>).MakeGenericType(someType); …
David Perlman
  • 1,460
  • 1
  • 12
  • 32
3
votes
1 answer

How to create a navigation property with a key that is not the the primary key of the 2nd object?

In EF5, using a code first approach and fluent API, how can create a navigation property (many to 1) based on a key that is not the primary key of the other table? My database model is as such, and I can't change it : TableFoo1 Foo1ID int…
Tipx
  • 7,367
  • 4
  • 37
  • 59
3
votes
4 answers

Why is a fluent implementation slower than a non-fluent one?

I wrote some test code that compares the speed of using the append() method of StringBuilder eight times sequentially as a fluent interface against invoking it separately in 8 lines. As fluent: StringBuilder s = new…
Bohemian
  • 412,405
  • 93
  • 575
  • 722
3
votes
1 answer

Many-to-Many Relations with 'code first' in Entity Framework 5 (EF5 - final release) wtih VS2012

I had invest now one day to find a solution wihtout success. I like to create a simple Many to Many relation. For that I've created two Models: A Player class where i will have the 'Turnaments' navigation property to see which turnaments has visit a…
3
votes
1 answer

Fluent interfaces (method chaining) with backwards navigation

I need to build a class which makes use of method chaining. I understand the concept of method chaining. Example: class Company { private String companyName; public setCompanyName(String companyName) { this.companyName =…
w00
  • 26,172
  • 30
  • 101
  • 147
2
votes
2 answers

Thread safety of a fluent like class using clone() and non final fields

This fluent like class is not strictly immutable because the fields are not final, but is it thread safe, and why? The thread safety issue I'm concerned with is not the race condition, but the visibility of the variables. I know there is a…
Emmanuel Bourg
  • 9,601
  • 3
  • 48
  • 76
2
votes
2 answers

Entity Framework Code First - Can an existing table be mapped and made read only?

I need to use the users table from a parent site, is it possible to map the user table using the fluent API and have it be read only?
Mantisimo
  • 4,203
  • 5
  • 37
  • 55
2
votes
3 answers

How to design a fluent interface (for exception handling)?

I am reviewing part of a code base, and I come to the exception handling part which is really messy. I would like to replace it with something more elegant. Then I thought it might not be a bad idea if I could have a fluent interface in place that…
Beatles1692
  • 5,214
  • 34
  • 65
2
votes
1 answer

Castle Windsor Fluent API: How to set a component parameter value to a configured property

I am just getting started with the Fluent registration for Castle Windsor and cant figure out how I can reference properties I have defined in the properties section of my XML configuration file when registering. So I have this code to register a…
nickc
  • 291
  • 2
  • 12
2
votes
1 answer

EF 4.1: Mapping a many-to-many relationship with composite keys and a shared column?

I'm using EF 4.1 Code First and trying to model the following. public class Apple { public int Id {get;set;} } public class Banana { public int AppleId {get;set;} public int Id {get;set;} public virtual ICollection