Skip to Content
함수형 프로그래밍 with 자바
book

함수형 프로그래밍 with 자바

by 벤 바이디히, 허귀영
March 2024
Beginner to intermediate
528 pages
10h 48m
Korean
Hanbit Media, Inc.
Content preview from 함수형 프로그래밍 with 자바
163
CHAPTER 05
레코드
}
}
var sourcePoint
=
new Point
(
23
,
42
);
//
=>
Point
[
x
=
23
,
y
=
42
]
var modifiedPoint
=
sourcePoint
.
with
().
x
(
5
);
//
=>
Point
[
x
=
5
,
y
=
42
]
기본 레코드에는 하나의 추가 메서드만 있고 모든
mutator
/
copy
메서드는
with
타입으로 캡
슐화됩니다.
wither
메서드의 한계는
5
장의 ‘컴포넌트의 기본값과 컴팩트 생성자’에서 설명한 것처럼, 각
컴포넌트마다 메서드를 작성해야 한다는 점입니다. 코드는 일반적인 시나리오에 초점을 맞
추는 것이 바람직하며, 필요에 따라서 새로운 메서드를 추가하는 것을 권장합니다.
빌더 패턴
5
장의 ‘단계별 생성’에서 소개된 빌더 패턴은 복제 생성자를 도입하여 변경을 보다 쉽게 관리
할 수 있습니다. 이러한 생성자를 사용하고 기존 레코드로 빌더를 초기화한 후, 필요한 변경
을 수행하고 새로운 레코드를 생성할 수 있습니다.
public record Point
(
int x
,
int y
)
{
public static final class Builder
{
private int x
;
private int y
;
public Builder
(
Point point
)
{
this
.
x
=
point
.
x
();
this
.
y
=
point ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

실무로 통하는 클린 코드

실무로 통하는 클린 코드

막시밀리아노 콘티에리

Publisher Resources

ISBN: 9791169212175