You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A fluent interface provides an easy-readable, flowing interface, that often mimics a domain specific
12
-
language. Using this pattern results in code that can be read nearly as human language.
20
+
A fluent interface provides an easy-readable, flowing interface, that often mimics a domain specific language. Using this pattern results in code that can be read nearly as human language.
13
21
14
22
## Explanation
15
23
@@ -24,18 +32,15 @@ A fluent interface can be implemented using any of
24
32
25
33
Real world example
26
34
27
-
> We need to select numbers based on different criteria from the list. It's a great chance to
28
-
> utilize fluent interface pattern to provide readable easy-to-use developer experience.
35
+
> We need to select numbers based on different criteria from the list. It's a great chance to utilize fluent interface pattern to provide readable easy-to-use developer experience.
> In software engineering, a fluent interface is an object-oriented API whose design relies
37
-
> extensively on method chaining. Its goal is to increase code legibility by creating a
38
-
> domain-specific language (DSL).
43
+
> In software engineering, a fluent interface is an object-oriented API whose design relies extensively on method chaining. Its goal is to increase code legibility by creating a domain-specific language (DSL).
39
44
40
45
**Programmatic Example**
41
46
@@ -70,72 +75,72 @@ The `SimpleFluentIterable` evaluates eagerly and would be too costly for real wo
* Builders in libraries like Apache Camel for integration workflows.
178
+
179
+
## Consequences
180
+
181
+
Benefits:
182
+
183
+
* Improved code readability and maintainability.
184
+
* Encourages building immutable objects since methods typically return new instances.
185
+
* Reduces the need for variables as the context is maintained in the chain.
186
+
187
+
Trade-offs:
188
+
189
+
* Can lead to less intuitive code for those unfamiliar with the pattern.
190
+
* Debugging can be challenging due to the chaining of method calls.
191
+
* Overuse can lead to complex and hard-to-maintain code structures.
192
+
193
+
## Related Patterns
194
+
195
+
*[Builder](https://java-design-patterns.com/patterns/builder/): Often implemented using a Fluent Interface to construct objects step-by-step. The Builder Pattern focuses on constructing complex objects, while Fluent Interface emphasizes the method chaining mechanism.
196
+
*[Chain of Responsibility](https://java-design-patterns.com/patterns/chain-of-responsibility/): Fluent Interfaces can be seen as a specific utilization of the Chain of Responsibility, where each method in the chain handles a part of the task and then delegates to the next method.
171
197
172
198
## Credits
173
199
174
200
*[Fluent Interface - Martin Fowler](http://www.martinfowler.com/bliki/FluentInterface.html)
175
201
*[Evolutionary architecture and emergent design: Fluent interfaces - Neal Ford](http://www.ibm.com/developerworks/library/j-eaed14/)
*[Domain Specific Languages](https://www.amazon.com/gp/product/0321712943/ref=as_li_tl?ie=UTF8&tag=javadesignpat-20&camp=1789&creative=9325&linkCode=as2&creativeASIN=0321712943&linkId=ad8351d6f5be7d8b7ecdb650731f85df)
0 commit comments