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
32
votes
5 answers

Fluent interface in Delphi

What are the pros and cons in using fluent interfaces in Delphi? Fluent interfaces are supposed to increase the readability, but I'm a bit skeptical to have one long LOC that contains a lot of chained methods. Are there any compiler issues? Are…
Jørn E. Angeltveit
  • 3,029
  • 3
  • 22
  • 53
32
votes
7 answers

EF Code First prevent property mapping with Fluent API

I have a class Product and a complex type AddressDetails public class Product { public Guid Id { get; set; } public AddressDetails AddressDetails { get; set; } } public class AddressDetails { public string City { get; set; } public…
Catalin
  • 11,503
  • 19
  • 74
  • 147
31
votes
10 answers

How to store double[] array to database with Entity Framework Code-First approach

How can I store an array of doubles to database using Entity Framework Code-First with no impact on the existing code and architecture design? I've looked at Data Annotation and Fluent API, I've also considered converting the double array to a…
jonas
  • 1,592
  • 3
  • 20
  • 29
28
votes
19 answers

Design of an Alternative (Fluent?) Interface for Regular Expressions

I've just seen a huge regex for Java that made me think a little about maintainability of regular expressions in general. I believe that most people - except some badass perl mongers - would agree that regular expressions are hardly maintainable. I…
sfussenegger
  • 35,575
  • 15
  • 95
  • 119
27
votes
7 answers

What's the point of DSLs / fluent interfaces

I was recently watching a webcast about how to create a fluent DSL and I have to admit, I don't understand the reasons why one would use such an approach (at least for the given example). The webcast presented an image resizing class, that allows…
M4N
  • 94,805
  • 45
  • 217
  • 260
27
votes
6 answers

Partial generic type inference possible in C#?

I am working on rewriting my fluent interface for my IoC class library, and when I refactored some code in order to share some common functionality through a base class, I hit upon a snag. Note: This is something I want to do, not something I have…
Lasse V. Karlsen
  • 380,855
  • 102
  • 628
  • 825
25
votes
1 answer

Difference between .WithMany() and .WithOptional()?

Below are two similar fluent API configurations: WithMany() modelBuilder.Entity() .HasRequired(cou => cou.Currency) .WithMany() .WillCascadeOnDelete(false);…
Ingmar
  • 571
  • 2
  • 6
  • 13
22
votes
8 answers

C#: Returning 'this' for method nesting?

I have a class that I have to call one or two methods a lot of times after each other. The methods currently return void. I was thinking, would it be better to have it return this, so that the methods could be nested? or is that considerd very very…
Svish
  • 152,914
  • 173
  • 462
  • 620
20
votes
1 answer

MEF Plugins and EF CodeFirst - How?

Background: We have a project with many modules. We're using EntityFramework 4.2 with FluentAPI (CodeFirst). There is a central project named Diverto.ORM.EntityFramework.SQLServer which contains partial classes that build the context using the…
19
votes
3 answers

Designing a fluent Javascript interface to abstract away the asynchronous nature of AJAX

How would I design an API to hide the asynchronous nature of AJAX and HTTP requests, or basically delay it to provide a fluent interface. To show an example from Twitter's new Anywhere API: // get @ded's first 20 statuses, filter only the tweets…
Anurag
  • 140,337
  • 36
  • 221
  • 257
18
votes
3 answers

The DELETE statement conflicted with the SAME TABLE REFERENCE constraint with Entity Framework

I have a table with a self reference where the ParentId is an FK to the ID (PK). Using EF (code-first), I've set up my relationship as follows: this.HasOptional(t => t.ParentValue) .WithMany(t => t.ChildValues) .HasForeignKey(t =>…
Kon
  • 27,113
  • 11
  • 60
  • 86
17
votes
3 answers

How to do a PHP nested class or nested methods?

How can I do this in PHP $myDBClass->users()->limit(5);//output you limited users to 5 $myDBClass->comments()->limit(3);//output you limited comments to 3 what I meant is nested methods or nested class (I don't know!) so when I call the limit…
ahmed
  • 14,316
  • 30
  • 94
  • 127
17
votes
2 answers

How to chain multiple re.sub() commands in Python

I would like to do multiple re.sub() replacements on a string and I'm replacing with different strings each time. This looks so repetitive when I have many substrings to replace. Can someone please suggest a nicer way to do this? stuff =…
JTFouquier
  • 389
  • 1
  • 4
  • 17
16
votes
4 answers

What's a fluent interface?

I recently came across this expression - but reading up on Wikipedia did not clarify it much for me - I still don't get it: What's the point of it How is it used in practice (i.e. how does it benefit a coder in their day to day work/building…
Stick it to THE MAN
  • 5,621
  • 17
  • 77
  • 93
15
votes
5 answers

Must a "fluent" (or chainable) method be immutable?

Say I have a class with some properties and some methods for manipulating those properties: public class PersonModel { public string Name { get; set; } public string PrimaryPhoneNumber { get; set; } public void…
user718642
1
2
3
29 30