This article will cover the fluent-API, what it is, and how you can take advantage of this design to make the code cleaner and valuable.
Join the DZone community and get the full member experience. We know that, in a software project, nothing replaces good documentation. However, it is also necessary to pay attention to how intuitive the written code is. After all, the simpler and more natural the code is, the better its experience for users. In the simple « programming rule », in which we will forget everything we have to remember, an API that « forces » you to remember is crucial proof of failure. That’s why, in this article, we’ll introduce the topic and show you how to create a fluid API from the Fluent-API concept. When we speak in the context of software engineering, a fluent-API is an object-oriented API whose design is largely based on method chaining. This concept, created in 2005 by Eric Evans and Martin Fowler, aims to increase code readability by creating a domain-specific language ( DSL). In practice, creating a fluent API means developing an API in which it is unnecessary to memorize the next steps or methods, allowing for a natural and continuous sequence as if it were a menu of options. This natural cadence works in a similar way to a restaurant or even a fast-food chain in that as you are putting together a dish, the options vary according to the choices you make. If, for example, you choose a chicken sandwich, the sides will be suggested considering the chosen dish and so on. In the Java world, we can think of two famous examples of this type of implementation. The first one is the JOOQ framework, a project led by Lukas Eder, which facilitates communication between Java and relational databases.
Home
United States
USA — software Fluent-API: Creating Easier, More Intuitive Code With a Fluent API