๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

DI2

Spring - ๋‹ค์–‘ํ•œ ์˜์กด๊ด€๊ณ„ ์ฃผ์ž… ๋ฐฉ๋ฒ• 1. ์ƒ์„ฑ์ž ์ฃผ์ž… ์ด๋ฆ„ ๊ทธ๋Œ€๋กœ ์ƒ์„ฑ์ž๋ฅผ ํ†ตํ•ด์„œ ์˜์กด ๊ด€๊ณ„๋ฅผ ์ฃผ์ž… ๋ฐ›๋Š” ๋ฐฉ๋ฒ• ํŠน์ง• ์ƒ์„ฑ์ž ํ˜ธ์ถœ์‹œ์ ์— ๋”ฑ 1๋ฒˆ๋งŒ ํ˜ธ์ถœ๋˜๋Š” ๊ฒƒ์ด ๋ณด์žฅ๋œ๋‹ค. ๋ถˆ๋ณ€, ํ•„์ˆ˜ ์˜์กด๊ด€๊ณ„์— ์‚ฌ์šฉ @Component public class OrderServiceImpl implements OrderService { private final MemberRepository memberRepository; private final DiscountPolicy discountPolicy; @Autowired public OrderServiceImpl(MemberRepository memberRepository, DiscountPolicy discountPolicy) { this.memberRepository = memberRepository; t.. 2023. 7. 12.
Spring - ์ง€๊ธˆ๊นŒ์ง€์˜ ์ „์ฒด ํ๋ฆ„ ์ •๋ฆฌ ์ง€๊ธˆ๊นŒ์ง€์˜ ์ฝ”๋“œ ์ƒˆ๋กœ์šด ํ• ์ธ ์ •์ฑ… ๊ฐœ๋ฐœ ์ƒˆ๋กœ์šด ํ• ์ธ ์ •์ฑ… ์ ์šฉ๊ณผ ๋ฌธ์ œ์  (dip, ocp ์œ„๋ฐ˜) ๊ด€์‹ฌ์‚ฌ์˜ ๋ถ„๋ฆฌ (์ถ”์ƒํ™”์—๋งŒ ์˜์กด, ๊ตฌ์ฒดํ™”์—๋Š” ์˜์กด๋„ ์—†๋„๋ก) AppConfig ๋ฆฌํŒฉํ„ฐ๋ง (์ „์ฒด ์•ฑ์„ ๊ตฌ์„ฑํ•˜๋Š” ๊ธฐ๋Šฅ์„ ๋”ฐ๋กœ appconfig๋กœ ๋นผ๋‘ ) ์ƒˆ๋กœ์šด ๊ตฌ์กฐ์™€ ํ• ์ธ ์ •์ฑ… ์ ์šฉ ์ƒˆ๋กœ์šด ํ• ์ธ ์ •์ฑ… ๊ฐœ๋ฐœ ๋‹คํ˜•์„ฑ ๋•๋ถ„์— ์ƒˆ๋กœ์šด ์ •๋ฅ  ํ• ์ธ ์ •์ฑ… ์ฝ”๋“œ๋ฅผ ์ถ”๊ฐ€๋กœ ๊ฐœ๋ฐœํ•˜๋Š” ๊ฒƒ ์ž์ฒด๋Š” ์•„๋ฌด ๋ฌธ์ œ๊ฐ€ ์—†์Œ ์ƒˆ๋กœ์šด ํ• ์ธ ์ •์ฑ… ์ ์šฉ๊ณผ ๋ฌธ์ œ์  ์ƒˆ๋กœ ๊ฐœ๋ฐœํ•œ ์ •๋ฅ  ํ• ์ธ ์ •์ฑ…์„ ์ ์šฉํ•˜๋ ค๊ณ  ํ•˜๋‹ˆ ํด๋ผ์ด์–ธํŠธ ์ฝ”๋“œ์ธ ์ฃผ๋ฌธ ์„œ๋น„์Šค ๊ตฌํ˜„์ฒด๋„ ํ•จ๊ป˜ ๋ณ€๊ฒฝํ•ด์•ผํ•จ ์ฃผ๋ฌธ ์„œ๋น„์Šค ํด๋ผ์ด์–ธํŠธ๊ฐ€ ์ธํ„ฐํŽ˜์ด์Šค์ธ DiscountPolicy ๋ฟ๋งŒ ์•„๋‹ˆ๋ผ, ๊ตฌ์ฒด ํด๋ž˜์Šค์ธ FixDiscountPolicy ๋„ ํ•จ๊ป˜ ์˜์กด -> DIP ์œ„๋ฐ˜ AppConfig ๋ฆฌํŒฉํ„ฐ๋ง ๊ตฌ์„ฑ .. 2023. 7. 7.