DevOps Articles

Curated articles, resources, tips and trends from the DevOps World.

Why Builder Is Often an Antipattern and How to Replace it With Fluent Build

4 years ago dzone.com

Summary: This is a summary of an article originally published by the source. Read the full original article here →

Unfortunately, it's often misunderstood and incorrectly applied, which results to runtime errors. Let's remember the purpose of Builder: set only necessary fields in some object and keep remaining fields set to default values.

A traditional Builder class would look like this: One important observation: every setter returns this and this in turn allows users of this call to invoke every method available in builder.

To do this, we can return dedicated interfaces instead of this and let Builder implement all these interfaces: Huh.

But, much more importantly, we can omit whole setters and mutable fields boilerplate in the builder, which significantly reduces the amount of code.

Made with pure grit © 2024 Jetpack Labs Inc. All rights reserved. www.jetpacklabs.com