Today post is a very simple post about Fluent Apis/Fluent Interfaces. These days while developing apps, I am coming across lot of api's that are following Fluent Api style. For example lot of Entity framework api's.
Fluent Api's is a way of expressing you api's in a chained fashion. More like functional programming. Advantage are code becomes more readable and easier to understand.
For example:
Here in the Person class, I am setting the member varaibles like FirstName, LastName, Age in Fluent Apis. The idea here is to return the object after setting up the appropriate properties.

This is a very basic example but this can be exdended to complex object in which processing is done in methods and they return the same object back, so that other methods/properties can be chained.
-Yashwant
0 comments:
Post a Comment