Build Beautiful, Fluent APIs With The Builder Design Pattern

Friday, Aug 16 2:45 PM - 3:45 PM Junior Ballroom D

Description

Have you ever seen code that looks like this?

employee = Employee.firstName("Kelly").lastName("Morrison").title("Solutions Architect").department("Engineering")

This is an example of a fluent API, an API that uses chained and well-named methods to construct an object. Fluent APis make it a joy for users to work with your code, and they are used in many common libraries and frameworks. This presentation will explain what a fluent API is, and how it may be constructed using the Builder design pattern. The audience will see examples in both Java and TypeScript, and will leave with an understanding of what a Fluent API is, how to create one using the Builder design pattern, and how to leverage IDEs and ChatGPT to help create one. The intended audience is a strong beginner or intermediate programmer that knows how to write classes and wants to "level up" their technique.

We'll begin with a look at the Builder design pattern: what it is, what it's for, and how to implement it. We'll see how to use IDEs to generate them for us, how to tweak the generated code to make it easier to use, and how to write the code from scratch. We will write a couple of simple Builders to illustrate.

Next, we'll look at how to use multiple Builders to create an API that gently guides the user along different paths when constructing an object. We'll also see how to use Builders to make an immutable class that is better suited for concurrent programming.

We will wrap up the session with a question period, and then provide links to the slides for the presentation and a list of resources for further information.