π 2024λ 01μ 23μΌ
- λΉλ ν¨ν΄(Builder Pattern)μ κ°μ²΄ μμ±κ³Όμ μ ν¨κ³Όμ μΌλ‘ μΆμννκ³ λ³΅μ‘ν κ°μ²΄λ₯Ό μμ±νλ λμμΈ ν¨ν΄μ΄λ€.
- μΌλ°μ μΌλ‘ κ°μ²΄λ₯Ό μμ±νλλ° λ§μ νλΌλ―Έν°κ° νμνκ±°λ, μμ±μμ λ§μ μΈμλ₯Ό μ λ¬νλ κ²μ΄ 볡μ‘νκ³ νΌλμ€λ¬μΈ λ λΉλ ν¨ν΄μ΄ μ μ©
λΉλ ν¨ν΄μ κ΅¬μ± μμ κ΅¬μ± μμ μ€λͺ Product
(μμ±λ κ°μ²΄)λΉλ ν¨ν΄μ ν΅ν΄ μμ±λ κ°μ²΄λ₯Ό λνλ Builder Interface
(λΉλ μΈν°νμ΄μ€)κ°μ²΄λ₯Ό μμ±νλλ° νμν λ¨κ³λ€μ μ μν μΈν°νμ΄μ€ Concrete Builder
(ꡬ체μ μΈ λΉλ)Builder μΈν°νμ΄μ€λ₯Ό ꡬννμ¬ μ€μ λ‘ κ°μ²΄λ₯Ό μμ±νλ ν΄λμ€ Director
(κ°μ²΄ μμ±μ μ§μνλ ν΄λμ€)λΉλ μΈν°νμ΄μ€λ₯Ό ν΅ν΄ κ°μ²΄λ₯Ό μμ±νκ³ , νμν νλΌλ―Έν°λ₯Ό μ€μ νλ ν΄λμ€ @Entity @Getter /* @Builder ν΅ν΄ λΉλν¨ν΄μΌλ‘ κ°μ²΄ μμ± λ§€κ°λ³μμ μν μμ, 맀κ°λ³μμ κ°μ λ±μ μ μ°νκ² μΈν */ @Builder @AllArgsConstructor @NoArgsConstructor public class Author { }
Hello ν΄λμ€ λΉλν¨ν΄ λ§λ€μ΄λ³΄κΈ°
@Data @NoArgsConstructor public class Hello { private String name; private String email; private String password; public Hello (MyBuilder myBuilder){ this.name = myBuilder.name; this.email = myBuilder.email; this.password = myBuilder.password; } public static MyBuilder builder(){ return new MyBuilder(); } public static class MyBuilder{ private String name; private String email; private String password; public MyBuilder name(String name){ this.name = name; return this; } public MyBuilder email(String email){ this.email = email; return this; } public MyBuilder password(String password){ this.password = password; return this; } public Hello build(){ return new Hello(this); } } }