10
Design Pattern: Fluent Interface” Leandro da costa gonçalves

Design pattern fluent interface

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: Design pattern   fluent interface

Design Pattern: “Fluent Interface”Leandro da costa gonçalves

Page 2: Design pattern   fluent interface

Eric Evans e Fowler

Page 3: Design pattern   fluent interface

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

Page 4: Design pattern   fluent interface

More Readable

Page 5: Design pattern   fluent interface

Traditional

Page 6: Design pattern   fluent interface

Fluent Interface

Page 7: Design pattern   fluent interface

Traditional

Page 8: Design pattern   fluent interface

Fluent Interface

Page 9: Design pattern   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

Page 10: Design pattern   fluent interface

Let's practice

Implement an algorithm to change one burned lamp.