From df2161b1af8dd663559c24dd142e031feb540686 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Dyda?= Date: Tue, 25 Oct 2022 20:02:48 +0200 Subject: [PATCH] Builder design pattern for Address class - with defaults. --- .../02/src/main/java/pl/amu/edu/demo/data/Address.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/demo/02/src/main/java/pl/amu/edu/demo/data/Address.java b/demo/02/src/main/java/pl/amu/edu/demo/data/Address.java index 6e13044..9343dc0 100644 --- a/demo/02/src/main/java/pl/amu/edu/demo/data/Address.java +++ b/demo/02/src/main/java/pl/amu/edu/demo/data/Address.java @@ -2,12 +2,20 @@ package pl.amu.edu.demo.data; import lombok.AccessLevel; import lombok.AllArgsConstructor; +import lombok.Builder; import lombok.experimental.FieldDefaults; -@AllArgsConstructor +@AllArgsConstructor(access = AccessLevel.PRIVATE) @FieldDefaults(level = AccessLevel.PUBLIC, makeFinal = true) +@Builder(builderClassName = "AddressBuilder", setterPrefix = "with") public class Address { String addressLine1; String addressLine2; String zipCode; } + +final class AddressBuilder { + String addressLine1; + String addressLine2 = null; + String zipCode; +}