Design Pattern: “Fluent Interface” Leandro da costa gonçalves
Eric Evans e Fowler
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
More Readable
Traditional
Fluent Interface
Traditional
Fluent Interface
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
Let's practice  Implement an algorithm to change one burned lamp.

Design pattern fluent interface

  • 1.
  • 2.
  • 3.
    The Fluent InterfacePattern 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
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
    When to useFluent 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
  • 10.
    Let's practice  Implementan algorithm to change one burned lamp.