티스토리 뷰

SpringBoot

ChainMethod 기법

VIRGIL ABLOH 2021. 8. 4. 12:27
반응형
package com.demo.domain;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@AllArgsConstructor // 모든 생성자
@NoArgsConstructor // 빈 생성자
@Data // getter, setter, ToString
public class AccntInfo {

    String cstmrCode;
    String accnt;
    String createdAt;
    long blce;

    public AccntInfo cSetCstmrCode(String cstmrCode) {
        this.cstmrCode = cstmrCode;
        return this;
    }

    public AccntInfo cSetAccnt(String accnt) {
        this.accnt = accnt;
        return this;
    }

    public AccntInfo cSetCreatedAt(String createdAt) {
        this.createdAt = createdAt;
        return this;
    }

    public AccntInfo cSetBlce(long blce) {
        this.blce = blce;
        return this;
    }
}
package com.demo;

import com.demo.domain.AccntInfo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class DemoApplication {

	public static void main(String[] args) {
		SpringApplication.run(DemoApplication.class, args);

		new AccntInfo().cSetAccnt("asdasd").cSetBlce(1234L);
	}
}

이렇게 쓰면 한줄로 체인처럼 메서드를 호출할 수 있기에 가독성을 높인다.

반응형
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
TAG
more
«   2026/06   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
글 보관함