Creating Intuitive APIs With The Builder Design Pattern
This session will level up your programming skills by introducing the Builder design pattern. It's used in many modern languages and libraries, and you've probably seen it before. Have you ever used an API that looks like this?
pizza = Pizza.large().regularSauce().pepperoni().bake()
That's an example of the Builder pattern. In this session, we'll discover why the pattern is commonly used and how to incorporate it in your own programs.
We'll begin with a code free introduction that shows how the pattern is similar to ordering a meal in a diner. Then we'll see how to implement it in Java.
Next, we'll take an increasingly deep dive into the pattern. You'll learn:
- why the pattern is better than adding setters to a class
- the advantages of Builders in concurrent programming
- several examples of using the Builder pattern in everyday programming
- expert guidance on when to use Builders (and when NOT to)
- how IDEs like IntelliJ can create Builders for you (and why you're better off writing your own)
- using Lombok to implement Builders for older versions of Java
- hints for implementing Builders using Java 14 records
- extending the Builder pattern to TypeScript and Go
- how to effectively prompt ChatGPT to write a Builder for you
- applying the pattern to break a complex API into a simpler, fluent one, such as the API used by ArchUnit
- leveraging the pattern to create your own DSLs (domain specific languages)
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.
This talk is intended for strong beginners, intermediate programmers, or experienced programmers unfamiliar with the pattern. Many of the examples are in Java, but the focus of the talk is language independent, and some examples will be given for Go and TypeScript.