diff --git a/hw-03/project-root/app/src/main/java/org/example/App.java b/hw-03/project-root/app/src/main/java/org/example/App.java index 71bd80c..51f8968 100644 --- a/hw-03/project-root/app/src/main/java/org/example/App.java +++ b/hw-03/project-root/app/src/main/java/org/example/App.java @@ -4,6 +4,7 @@ package org.example; import org.example.adapter.*; +import org.example.builder.*; public class App { public static void main(String[] args) { @@ -12,6 +13,7 @@ public class App { private static void run() { checkAdapterPattern(); + checkBuilderPattern(); } private static void checkAdapterPattern() { @@ -20,4 +22,11 @@ public class App { target.methodWithoutArguments(); } + + private static void checkBuilderPattern() { + Product product = + new ProductBuilder().setFirst("first").setSecond("second").setThird(3).build(); + + System.out.println(product); + } } diff --git a/hw-03/project-root/app/src/main/java/org/example/builder/Product.java b/hw-03/project-root/app/src/main/java/org/example/builder/Product.java index e69de29..27c8f92 100644 --- a/hw-03/project-root/app/src/main/java/org/example/builder/Product.java +++ b/hw-03/project-root/app/src/main/java/org/example/builder/Product.java @@ -0,0 +1,40 @@ +package org.example.builder; + +/** Product */ +public class Product { + private final String first; + private final String second; + private final int third; + + public Product(String first, String second, int third) { + this.first = first; + this.second = second; + this.third = third; + } + + public String getFirst() { + return first; + } + + public String getSecond() { + return second; + } + + public int getThird() { + return third; + } + + @Override + public String toString() { + return "Product{" + + "first='" + + first + + '\'' + + ", second='" + + second + + '\'' + + ", third=" + + third + + '}'; + } +} diff --git a/hw-03/project-root/app/src/main/java/org/example/builder/ProductBuilder.java b/hw-03/project-root/app/src/main/java/org/example/builder/ProductBuilder.java index e69de29..7afda6f 100644 --- a/hw-03/project-root/app/src/main/java/org/example/builder/ProductBuilder.java +++ b/hw-03/project-root/app/src/main/java/org/example/builder/ProductBuilder.java @@ -0,0 +1,27 @@ +package org.example.builder; + +/** Builder */ +public class ProductBuilder { + private String first; + private String second; + private int third; + + public ProductBuilder setFirst(String first) { + this.first = first; + return this; + } + + public ProductBuilder setSecond(String second) { + this.second = second; + return this; + } + + public ProductBuilder setThird(int third) { + this.third = third; + return this; + } + + public Product build() { + return new Product(first, second, third); + } +}