๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๋ฐ˜์‘ํ˜•

gof1

[JAVA] ์ •์  ํŒฉํ† ๋ฆฌ ๋ฉ”์†Œ๋“œ๋ž€? (static factory method) ์ •์  ํŒฉํ† ๋ฆฌ ๋ฉ”์„œ๋“œ ์ •์ (static), ํŒฉํ† ๋ฆฌ(factory), ๋ฉ”์„œ๋“œ(method) GoF๋ผ๋Š” ๋””์ž์ธ ํŒจํ„ด ์ค‘ ํŒฉํ† ๋ฆฌ ํŒจํ„ด์—์„œ ์œ ๋ž˜ํ•œ ๋‹จ์–ด๋กœ ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•˜๋Š” ์—ญํ• ์„ ๋ถ„๋ฆฌํ•˜๊ฒ ๋‹ค๋Š” ๊ฒƒ์„ ๋งํ•œ๋‹ค. (ํ•˜์ง€๋งŒ ์ •์  ํŒฉํ† ๋ฆฌ ๋ฉ”์„œ๋“œ์™€ ํŒฉํ† ๋ฆฌ ํŒจํ„ด์€ ๋ช…ํ™•ํ•˜๊ฒŒ ๋‹ค๋ฅด๊ณ , ๋””์ž์ธ ํŒจํ„ด ์ค‘์— ์ด์™€ ์ผ์น˜ํ•˜๋Š” ํŒจํ„ด์ด ์—†๋‹ค๊ณ  ํ•œ๋‹ค. ์ด ๋ถ€๋ถ„์— ๋Œ€ํ•ด์„  ๊ณต๋ถ€๋ฅผ ํ•ด๋ด์•ผ๊ฒ ๋‹ค..) ์ข€ ๋” ์‰ฝ๊ฒŒ ์„ค๋ช…ํ•˜์ž๋ฉด ์ƒ์„ฑ์ž๋ฅผ ํ†ตํ•ด ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•˜๋Š”๊ฒŒ ์•„๋‹ˆ๋ผ ๋ณ„๋„ ๋ฉ”์†Œ๋“œ๋ฅผ ์ •์˜ํ•ด์„œ ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•  ์ˆ˜ ์žˆ๋„๋ก ๊ฐ์ฒด ๋‚ด์— ์ •์  ๋ฉ”์†Œ๋“œ๋ฅผ ์ •์˜ํ•ด๋†“์€ ๊ฒƒ! ์ •ํ™•ํžˆ ์–ด๋–ค ๋ฉ”์†Œ๋“œ๋ฅผ ์–˜๊ธฐํ•˜๋Š” ๊ฑด์ง€ ์˜ˆ์‹œ๋ฅผ ๋“ค์–ด๋ณด๊ฒ ๋‹ค. java.time ํŒจํ‚ค์ง€์— ํฌํ•จ๋œ LocalDateTime ํด๋ž˜์Šค์˜ ์ •์  ํŒฉํ† ๋ฆฌ ๋ฉ”์„œ๋“œ๋ฅผ ์‚ดํŽด ๋ณด๋ฉด ์ƒ์„ฑ์ž๋ฅผ ํ†ตํ•ด ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•˜๋Š” ๊ฒƒ์ด ์•„๋‹ˆ๋ผ of ๋ฉ”์†Œ.. 2022. 1. 10.
728x90
๋ฐ˜์‘ํ˜•