SlideShare a Scribd company logo
The Fluent Interface Pattern

Lars-Erik Kindblad
Senior Consultant
Blog: kindblad.com
A common problem in most software projects

 Technical debts increases over time and the code gets harder and
  harder to maintain and add features to




                                                          | Sector, Alliance, Offering
Feature delivery for most projects

                              Technical debt


                                                Complex and messy code
                                               Code and logic is duplicated
                                               No common coding standard
Features Delivered




                                                   No strict architecture
                                                           ++




                                       Time




                                                                              | Sector, Alliance, Offering
Ideal Feature Delivery
Features Delivered




                               Time




                                              | Sector, Alliance, Offering
How to reach ideal delivery?
 Software development is complex
 Not a single solution but a mix of many different things
  •   Write a lot of code
  •   Important to understand the business model
  •   Readable & maintainable code over fancy code
  •   Simplicity over complexity
  •   Decide on a common coding standard
  •   Reuse code instead of code duplication
  •   Create a project framework with common code and logic
  •   Design Patterns – follow generic solutions to commonly occurring problems
      o 100s of design patterns exists
         – Factory Pattern, MVC Pattern, Command Pattern, Fluent Interface Pattern etc.
  • ++

                                                                                     | Sector, Alliance, Offering
The Fluent Interface Pattern

 One of many design patterns that can contribute to a better code
  base
 Fluent Interfaces makes the code easier to read and easier to use
  due to a simpler API that requires less code
 Consists of 2 principles:
  • Method chaining - Traditional code requires one line per command, method
    chaining allows multiple commands per line
  • More readable API – The code can be read like a sentence. Optional as it
    requires more typing due to longer names and more code to write
 Popular to use in frameworks: Moq, Fluent Nhibernate, FluentData
  etc.


                                                                    | Sector, Alliance, Offering
Example – Find a person
Traditional Code:




Fluent Interface Code:



Or:




                                                   | Sector, Alliance, Offering
A more readable Fluent Interface




Or:




                                         | Sector, Alliance, Offering
Designing Fluent Interfaces - Method vs. Property



                               Use a method when having to
                               accept one or more values


                               Use a property when not having
                               to accept any values


                               Use a method to finish the call




                                                      | Sector, Alliance, Offering
Traditional Code




                   | Sector, Alliance, Offering
Fluent Interface Code




                        | Sector, Alliance, Offering
Example #2 – A List of Persons
Traditional Code:




Fluent Code:




                                                     | Sector, Alliance, Offering
Traditional Code




                   | Sector, Alliance, Offering
Fluent Interface Step 1: Add Gateway Pattern




                                               | Sector, Alliance, Offering
Step 2: Add Fluent Interface Pattern




                                       | Sector, Alliance, Offering
Examples from other Frameworks
Moq:




FluentData:




                                               | Sector, Alliance, Offering
When to use Fluent Interfaces

 Anywhere where it makes the code easier to read and easier to use
 Typically in methods that are often invoked
 Together with the Gateway Pattern to hide complex 3rd party code or
  legacy code
 Frameworks




                                                          | Sector, Alliance, Offering
QUESTIONS?

             | Sector, Alliance, Offering
www.capgemini.com



The information contained in this presentation is proprietary. ©2010 Capgemini. All rights reserved

More Related Content

PPTX
Data Access - Best Practice
PPTX
Application Architecture by Lars-Erik Kindblad, Capgemini
PPTX
Introduction to FluentData - The Micro ORM
PPTX
Application Architecture April 2014
PPTX
Dependency Injection vs Service Locator - Best Practice
PPTX
Inversion of Control - Introduction and Best Practice
PPTX
Unit Tests are Overrated (NDCOslo 2013)
PPT
Mule anypoint exchange
Data Access - Best Practice
Application Architecture by Lars-Erik Kindblad, Capgemini
Introduction to FluentData - The Micro ORM
Application Architecture April 2014
Dependency Injection vs Service Locator - Best Practice
Inversion of Control - Introduction and Best Practice
Unit Tests are Overrated (NDCOslo 2013)
Mule anypoint exchange

What's hot (6)

PPT
Mule anypoint exchange
PPTX
The Single Responsibility Principle
PPT
Unit 15 cobra case
PPT
Real-world Entity Framework
PPT
A Model-Based Approach for Extracting Business Rules out of Legacy Informatio...
PPTX
The Business Case behind Cloud Computing - The risks and rewards
Mule anypoint exchange
The Single Responsibility Principle
Unit 15 cobra case
Real-world Entity Framework
A Model-Based Approach for Extracting Business Rules out of Legacy Informatio...
The Business Case behind Cloud Computing - The risks and rewards
Ad

Viewers also liked (20)

PPTX
Application Architecture
PDF
Application Layer in PHP
PDF
Ready or not: No UI vom Verschwinden des Graphical User Interfaces
PDF
Responsive Design - Quick & Dirty
PDF
Webinar: Responsive Design
PPTX
Avoid code duplication! Principles & Patterns
PDF
Systementwurf mit UML
PPTX
How to build more reliable, robust and scalable distributed systems
PDF
Anforderungsanalyse und UML Grundlagen
PDF
Domain Driven Design und Nosql
PDF
Mobile Patterns - Wie Apps und Co. digitale Interfaces revolutionieren
PPTX
Publish & Subscribe to events using an Event Aggregator
PPTX
Roadmap von Microsoft UI Technologien und Windows 8
PDF
Domain-driven design - eine Einführung
PDF
SwissICT Fachgruppe UX: Definition und Bedeutung von User Experience
PPTX
Message Oriented Architecture using NServiceBus
PDF
Beyond GUI - Die Zukunft digitaler Interfaces
PDF
Sci-Fi Interfaces - Innovationsmotor für Mensch-Maschine-Interfaces?
PPTX
Inversion of Control and Dependency Injection
PDF
Mobile Development mit ASP.NET MVC 4
Application Architecture
Application Layer in PHP
Ready or not: No UI vom Verschwinden des Graphical User Interfaces
Responsive Design - Quick & Dirty
Webinar: Responsive Design
Avoid code duplication! Principles & Patterns
Systementwurf mit UML
How to build more reliable, robust and scalable distributed systems
Anforderungsanalyse und UML Grundlagen
Domain Driven Design und Nosql
Mobile Patterns - Wie Apps und Co. digitale Interfaces revolutionieren
Publish & Subscribe to events using an Event Aggregator
Roadmap von Microsoft UI Technologien und Windows 8
Domain-driven design - eine Einführung
SwissICT Fachgruppe UX: Definition und Bedeutung von User Experience
Message Oriented Architecture using NServiceBus
Beyond GUI - Die Zukunft digitaler Interfaces
Sci-Fi Interfaces - Innovationsmotor für Mensch-Maschine-Interfaces?
Inversion of Control and Dependency Injection
Mobile Development mit ASP.NET MVC 4
Ad

Similar to The Fluent Interface Pattern (20)

PDF
Fluent Interfaces
PDF
Framework Engineering_Final
PDF
Framework Engineering
PPTX
Evolution of Patterns
PPTX
Design patterns
PDF
Smart Client Development
PDF
Essential Software Architecture - Chapter 1 Understanding Software Architectu...
PPTX
Common ASP.NET Design Patterns - Telerik India DevCon 2013
PPT
Avoiding Software Insanity
PPT
Software Factories in the Real World: How an IBM® WebSphere® Integration Fact...
PPTX
PPSX
Software engineering
PDF
Software Engineering The Multiview Approach And Wisdm
PDF
An Introduction to Software Architecture - Summary
PPT
A Software Factory Integrating Rational Team Concert and WebSphere tools
PDF
2011/2012 CAST report on Application Software Quality (CRASH)
PDF
Oos Short Q N
Fluent Interfaces
Framework Engineering_Final
Framework Engineering
Evolution of Patterns
Design patterns
Smart Client Development
Essential Software Architecture - Chapter 1 Understanding Software Architectu...
Common ASP.NET Design Patterns - Telerik India DevCon 2013
Avoiding Software Insanity
Software Factories in the Real World: How an IBM® WebSphere® Integration Fact...
Software engineering
Software Engineering The Multiview Approach And Wisdm
An Introduction to Software Architecture - Summary
A Software Factory Integrating Rational Team Concert and WebSphere tools
2011/2012 CAST report on Application Software Quality (CRASH)
Oos Short Q N

Recently uploaded (20)

PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Approach and Philosophy of On baking technology
PPTX
A Presentation on Artificial Intelligence
PDF
Empathic Computing: Creating Shared Understanding
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Encapsulation theory and applications.pdf
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PPTX
Cloud computing and distributed systems.
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
KodekX | Application Modernization Development
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Mobile App Security Testing_ A Comprehensive Guide.pdf
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Diabetes mellitus diagnosis method based random forest with bat algorithm
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
“AI and Expert System Decision Support & Business Intelligence Systems”
Encapsulation_ Review paper, used for researhc scholars
Approach and Philosophy of On baking technology
A Presentation on Artificial Intelligence
Empathic Computing: Creating Shared Understanding
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
20250228 LYD VKU AI Blended-Learning.pptx
Encapsulation theory and applications.pdf
Understanding_Digital_Forensics_Presentation.pptx
Review of recent advances in non-invasive hemoglobin estimation
Network Security Unit 5.pdf for BCA BBA.
NewMind AI Weekly Chronicles - August'25 Week I
Cloud computing and distributed systems.
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
KodekX | Application Modernization Development

The Fluent Interface Pattern

  • 1. The Fluent Interface Pattern Lars-Erik Kindblad Senior Consultant Blog: kindblad.com
  • 2. A common problem in most software projects  Technical debts increases over time and the code gets harder and harder to maintain and add features to | Sector, Alliance, Offering
  • 3. Feature delivery for most projects Technical debt Complex and messy code Code and logic is duplicated No common coding standard Features Delivered No strict architecture ++ Time | Sector, Alliance, Offering
  • 4. Ideal Feature Delivery Features Delivered Time | Sector, Alliance, Offering
  • 5. How to reach ideal delivery?  Software development is complex  Not a single solution but a mix of many different things • Write a lot of code • Important to understand the business model • Readable & maintainable code over fancy code • Simplicity over complexity • Decide on a common coding standard • Reuse code instead of code duplication • Create a project framework with common code and logic • Design Patterns – follow generic solutions to commonly occurring problems o 100s of design patterns exists – Factory Pattern, MVC Pattern, Command Pattern, Fluent Interface Pattern etc. • ++ | Sector, Alliance, Offering
  • 6. The Fluent Interface Pattern  One of many design patterns that can contribute to a better code base  Fluent Interfaces makes the code easier to read and easier to use due to a simpler API that requires less code  Consists of 2 principles: • Method chaining - Traditional code requires one line per command, method chaining allows multiple commands per line • More readable API – The code can be read like a sentence. Optional as it requires more typing due to longer names and more code to write  Popular to use in frameworks: Moq, Fluent Nhibernate, FluentData etc. | Sector, Alliance, Offering
  • 7. Example – Find a person Traditional Code: Fluent Interface Code: Or: | Sector, Alliance, Offering
  • 8. A more readable Fluent Interface Or: | Sector, Alliance, Offering
  • 9. Designing Fluent Interfaces - Method vs. Property Use a method when having to accept one or more values Use a property when not having to accept any values Use a method to finish the call | Sector, Alliance, Offering
  • 10. Traditional Code | Sector, Alliance, Offering
  • 11. Fluent Interface Code | Sector, Alliance, Offering
  • 12. Example #2 – A List of Persons Traditional Code: Fluent Code: | Sector, Alliance, Offering
  • 13. Traditional Code | Sector, Alliance, Offering
  • 14. Fluent Interface Step 1: Add Gateway Pattern | Sector, Alliance, Offering
  • 15. Step 2: Add Fluent Interface Pattern | Sector, Alliance, Offering
  • 16. Examples from other Frameworks Moq: FluentData: | Sector, Alliance, Offering
  • 17. When to use Fluent Interfaces  Anywhere where it makes the code easier to read and easier to use  Typically in methods that are often invoked  Together with the Gateway Pattern to hide complex 3rd party code or legacy code  Frameworks | Sector, Alliance, Offering
  • 18. QUESTIONS? | Sector, Alliance, Offering
  • 19. www.capgemini.com The information contained in this presentation is proprietary. ©2010 Capgemini. All rights reserved