package dh0023.springcore.member.domain;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
public class Member {
private Long id;
private String name;
private Grade grade;
}
@NoArgsConstructor
@AllArgsConstructor
public class Member {
private Long id;
private String name;
private Grade grade;
}
@Component
public class OrderServiceImpl implements OrderService{
// final은 반드시 값이 있어야한다.
private final MemberRepository memberRepository;
private final DiscountPolicy discountPolicy;
public OrderServiceImpl(MemberRepository memberRepository, DiscountPolicy discountPolicy) {
this.memberRepository = memberRepository;
this.discountPolicy = discountPolicy;
}
}
@Component
@RequiredArgsConstructor
public class OrderServiceImpl implements OrderService{
// final은 반드시 값이 있어야한다.
private final MemberRepository memberRepository;
private final DiscountPolicy discountPolicy;
}
@Getter
@Setter
@ToString(exclude = "grade")
@AllArgsConstructor
public class Member {
private Long id;
private String name;
private Grade grade;
}
public class LombokTest {
@Test
@DisplayName("toString() 테스트")
void getToString() {
Member member = new Member(1L, "test123", Grade.VIP);
System.out.println(member);
}
}
Member(id=1, name=test123)
Process finished with exit code 0
public class Item {
private final String itemCd; // 필수
private final String itemNm; // 필수
private final String ctgId; // 필수
private final BigDecimal price; // 선택
private final String sellTypeCd; // 선택
public static class Builder {
private final String itemCd; // 필수
private final String itemNm; // 필수
private final String ctgId; // 필수
// 선택적 매개변수는 default 값으로 초기화
private BigDecimal price = BigDecimal.ZERO;
private String sellTypeCd = "00";
public Builder(String itemCd, String itemNm, String ctgId){
this.itemCd = itemCd;
this.itemNm = itemNm;
this.ctgId = ctgId;
}
public Builder price(BigDecimal price){
this.price = price;
return this;
}
public Builder sellTypeCd(String sellTypeCd){
this.sellTypeCd = sellTypeCd;
return this;
}
public Item build(){
return new Item(this);
}
}
private Item(Builder builder){
itemCd = builder.itemCd;
itemNm = builder.itemNm;
ctgId = builder.ctgId;
price = builder.price;
sellTypeCd = builder.sellTypeCd;
}
}
@Builder
public class Item {
private final String itemCd; // 필수
private final String itemNm; // 필수
private final String ctgId; // 필수
private final BigDecimal price; // 선택
private final String sellTypeCd; // 선택
}
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//
package ch2.dahye.item2;
import java.math.BigDecimal;
public class Item {
private final String itemCd;
private final String itemNm;
private final String ctgId;
private final BigDecimal price;
private final String sellTypeCd;
Item(String itemCd, String itemNm, String ctgId, BigDecimal price, String sellTypeCd) {
this.itemCd = itemCd;
this.itemNm = itemNm;
this.ctgId = ctgId;
this.price = price;
this.sellTypeCd = sellTypeCd;
}
public static Item.ItemBuilder builder() {
return new Item.ItemBuilder();
}
public static class ItemBuilder {
private String itemCd;
private String itemNm;
private String ctgId;
private BigDecimal price;
private String sellTypeCd;
ItemBuilder() {
}
public Item.ItemBuilder itemCd(String itemCd) {
this.itemCd = itemCd;
return this;
}
public Item.ItemBuilder itemNm(String itemNm) {
this.itemNm = itemNm;
return this;
}
public Item.ItemBuilder ctgId(String ctgId) {
this.ctgId = ctgId;
return this;
}
public Item.ItemBuilder price(BigDecimal price) {
this.price = price;
return this;
}
public Item.ItemBuilder sellTypeCd(String sellTypeCd) {
this.sellTypeCd = sellTypeCd;
return this;
}
public Item build() {
return new Item(this.itemCd, this.itemNm, this.ctgId, this.price, this.sellTypeCd);
}
public String toString() {
return "Item.ItemBuilder(itemCd=" + this.itemCd + ", itemNm=" + this.itemNm + ", ctgId=" + this.ctgId + ", price=" + this.price + ", sellTypeCd=" + this.sellTypeCd + ")";
}
}
}
@Getter
@AllArgsConstructor
public class Parent {
private final String parentName;
private final int parentAge;
}
@Getter
public class Child extends Parent {
private final String childName;
private final int childAge;
@Builder
public Child(String parentName, int parentAge, String childName, int childAge) {
super(parentName, parentAge);
this.childName = childName;
this.childAge = childAge;
}
}
public class Child extends Parent {
private final String childName;
private final int childAge;
public Child(String parentName, int parentAge, String childName, int childAge) {
super(parentName, parentAge);
this.childName = childName;
this.childAge = childAge;
}
public static Child.ChildBuilder builder() {
return new Child.ChildBuilder();
}
public String getChildName() {
return this.childName;
}
public int getChildAge() {
return this.childAge;
}
public static class ChildBuilder {
private String parentName;
private int parentAge;
private String childName;
private int childAge;
ChildBuilder() {
}
public Child.ChildBuilder parentName(String parentName) {
this.parentName = parentName;
return this;
}
public Child.ChildBuilder parentAge(int parentAge) {
this.parentAge = parentAge;
return this;
}
public Child.ChildBuilder childName(String childName) {
this.childName = childName;
return this;
}
public Child.ChildBuilder childAge(int childAge) {
this.childAge = childAge;
return this;
}
public Child build() {
return new Child(this.parentName, this.parentAge, this.childName, this.childAge);
}
public String toString() {
return "Child.ChildBuilder(parentName=" + this.parentName + ", parentAge=" + this.parentAge + ", childName=" + this.childName + ", childAge=" + this.childAge + ")";
}
}
}
@SuperBuilder
public class Parent {
private final String parentName;
private final int parentAge;
}
@SuperBuilder
public class Child extends Parent {
private final String childName;
private final int childAge;
}
public class Parent {
private final String parentName;
private final int parentAge;
protected Parent(Parent.ParentBuilder<?, ?> b) {
this.parentName = b.parentName;
this.parentAge = b.parentAge;
}
public static Parent.ParentBuilder<?, ?> builder() {
return new Parent.ParentBuilderImpl();
}
private static final class ParentBuilderImpl extends Parent.ParentBuilder<Parent, Parent.ParentBuilderImpl> {
private ParentBuilderImpl() {
}
protected Parent.ParentBuilderImpl self() {
return this;
}
public Parent build() {
return new Parent(this);
}
}
public abstract static class ParentBuilder<C extends Parent, B extends Parent.ParentBuilder<C, B>> {
private String parentName;
private int parentAge;
public ParentBuilder() {
}
protected abstract B self();
public abstract C build();
public B parentName(String parentName) {
this.parentName = parentName;
return this.self();
}
public B parentAge(int parentAge) {
this.parentAge = parentAge;
return this.self();
}
public String toString() {
return "Parent.ParentBuilder(parentName=" + this.parentName + ", parentAge=" + this.parentAge + ")";
}
}
}
public class Child extends Parent {
private final String childName;
private final int childAge;
protected Child(Child.ChildBuilder<?, ?> b) {
super(b);
this.childName = b.childName;
this.childAge = b.childAge;
}
public static Child.ChildBuilder<?, ?> builder() {
return new Child.ChildBuilderImpl();
}
private static final class ChildBuilderImpl extends Child.ChildBuilder<Child, Child.ChildBuilderImpl> {
private ChildBuilderImpl() {
}
protected Child.ChildBuilderImpl self() {
return this;
}
public Child build() {
return new Child(this);
}
}
public abstract static class ChildBuilder<C extends Child, B extends Child.ChildBuilder<C, B>> extends ParentBuilder<C, B> {
private String childName;
private int childAge;
public ChildBuilder() {
}
protected abstract B self();
public abstract C build();
public B childName(String childName) {
this.childName = childName;
return this.self();
}
public B childAge(int childAge) {
this.childAge = childAge;
return this.self();
}
public String toString() {
String var10000 = super.toString();
return "Child.ChildBuilder(super=" + var10000 + ", childName=" + this.childName + ", childAge=" + this.childAge + ")";
}
}
}