๋ณธ๋ฌธ์œผ๋กœ ๊ฑด๋„ˆ๋›ฐ๊ธฐ

๐ŸŒˆ Chapter 8: ์˜์กด์„ฑ ๊ด€๋ฆฌํ•˜๊ธฐ

  • ํ˜‘๋ ฅ์€ ํ•„์ˆ˜์ ์ด์ง€๋งŒ ๊ณผ๋„ํ•œ ํ˜‘๋ ฅ์€ ์„ค๊ณ„๋ฅผ ๊ณค๊ฒฝ์— ๋น ํŠธ๋ฆด ์ˆ˜ ์žˆ๋‹ค. ํ˜‘๋ ฅ์€ ๊ฐ์ฒด๊ฐ€ ๋‹ค๋ฅธ ๊ฐ์ฒด์— ๋Œ€ํ•ด ์•Œ๊ฒƒ์„ ๊ฐ•์š”ํ•œ๋‹ค.
  • ๋‹ค๋ฅธ ๊ฐ์ฒด์™€ ํ˜‘๋ ฅํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” ๊ทธ๋Ÿฐ ๊ฐ์ฒด๊ฐ€ ์กด์žฌํ•œ๋‹ค๋Š” ์‚ฌ์‹ค์„ ์•Œ๊ณ  ์žˆ์–ด์•ผ ํ•œ๋‹ค. ๊ฐ์ฒด๊ฐ€ ์ˆ˜์‹ ํ•  ์ˆ˜ ์žˆ๋Š” ๋ฉ”์‹œ์ง€์— ๋Œ€ํ•ด์„œ๋„ ์•Œ๊ณ  ์žˆ์–ด์•ผ ํ•œ๋‹ค. ์ด๋Ÿฐ ์ง€์‹์ด ๊ฐ์ฒด ์‚ฌ์ด์˜ ์˜์กด์„ฑ์„ ๋‚ณ๋Š”๋‹ค.

๐Ÿ“š ์˜์กด์„ฑ ์ดํ•ดํ•˜๊ธฐโ€‹

๐ŸŽˆ ๋ณ€๊ฒฝ๊ณผ ์˜์กด์„ฑโ€‹

  • ์˜์กด์„ฑ์€ ์‹คํ–‰ ์‹œ์ ๊ณผ ๊ตฌํ˜„ ์‹œ์ ์— ์„œ๋กœ ๋‹ค๋ฅธ ์˜๋ฏธ๋ฅผ ๊ฐ€์ง„๋‹ค.
    • ์‹คํ–‰ ์‹œ์ : ์˜์กดํ•˜๋Š” ๊ฐ์ฒด๊ฐ€ ์ •์ƒ์ ์œผ๋กœ ๋™์ž‘ํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” ์‹คํ–‰ ์‹œ์— ์˜์กด ๋Œ€์ƒ ๊ฐ์ฒด๊ฐ€ ๋ฐ˜๋“œ์‹œ ์กด์žฌํ•ด์•ผ ํ•œ๋‹ค.
    • ๊ตฌํ˜„ ์‹œ์ : ์˜์กด ๋Œ€์ƒ ๊ฐ์ฒด๊ฐ€ ๋ณ€๊ฒฝ๋  ๊ฒฝ์šฐ ์˜์กดํ•˜๋Š” ๊ฐ์ฒด๋„ ํ•จ๊ป˜ ๋ณ€๊ฒฝ๋œ๋‹ค.
  • ๋‹ค์Œ์€ PeriodCondition ํด๋ž˜์Šค์˜ isSatisfiedBy ๋ฉ”์„œ๋“œ๋Š” Screening ์ธ์Šคํ„ด์Šค์—๊ฒŒ getStartTime ๋ฉ”์‹œ์ง€๋ฅผ ์ „์†กํ•œ๋‹ค.
public class PeriodCondition implements DiscountCondition {
private DayOfWeek dayOfWeek;
private LocalTime startTime;
private LocalTime endTime;

//...

public boolean isSatisfiedBy(Screening screening) {
return screening.getStartTime().getDayOfWeek().equals(dayOfWeek) &&
startTime.compareTo(screening.getStartTime().toLocalTime()) <= 0 &&
endTime.compareTo(screening.getStartTime().toLocalTime()) >= 0;
}
}
  • ์‹คํ–‰ ์‹œ์ ์— PeriodCondition์˜ ์ธ์Šคํ„ด์Šค๊ฐ€ ์ •์ƒ์ ์œผ๋กœ ๋™์ž‘ํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” Screening์˜ ์ธ์Šคํ„ด์Šค๊ฐ€ ์กด์žฌํ•ด์•ผ ํ•œ๋‹ค. ๋งŒ์•ฝ Screening์ธ์Šคํ„ด์Šค๊ฐ€ ์กด์žฌํ•˜์ง€ ์•Š์œผ๋ฉด ์˜ˆ์ƒํ–ˆ๋˜ ๋Œ€๋กœ ๋™์ž‘ํ•˜์ง€ ์•Š์„ ๊ฒƒ์ด๋‹ค.
  • ์ด์ฒ˜๋Ÿผ ์–ด๋–ค ๊ฐ์ฒด๊ฐ€ ์˜ˆ์ •๋œ ์ž‘์—…์„ ์ •์ƒ์ ์œผ๋กœ ์ˆ˜ํ–‰ํ•˜๊ธฐ ์œ„ํ•ด ๋‹ค๋ฅธ ๊ฐ์ฒด๋ฅผ ํ•„์š”๋กœ ํ•˜๋Š” ๊ฒฝ์šฐ ๋‘ ๊ฐ์ฒด ์‚ฌ์ด์— ์˜์กด์„ฑ์ด ์กด์žฌํ•œ๋‹ค๊ณ  ๋งํ•œ๋‹ค. ์˜์กด์„ฑ์€ ๋ฐฉํ–ฅ์„ฑ์„ ๊ฐ€์ง€๋ฉฐ ํ•ญ์ƒ ๋‹จ๋ฐฉํ–ฅ์ด๋‹ค.
  • ์ด ๊ฒฝ์šฐ PeriodCondition์€ Screening์— ์˜์กดํ•œ๋‹ค.
  • ๋‘ ์š”์†Œ ์‚ฌ์ด์˜ ์˜์กด์„ฑ์€ ์˜์กด๋˜๋Š” ์š”์†Œ๊ฐ€ ๋ณ€๊ฒฝ๋  ๋•Œ ์˜์กดํ•˜๋Š” ์š”์†Œ๋„ ํ•จ๊ป˜ ๋ณ€๊ฒฝ๋  ์ˆ˜ ์žˆ๋‹ค๋Š” ๊ฒƒ์„ ์˜๋ฏธํ•œ๋‹ค. ๋”ฐ๋ผ์„œ ์˜์กด์„ฑ์€ ๋ณ€๊ฒฝ์— ์˜ํ•œ ์˜ํ–ฅ์˜ ์ „ํŒŒ ๊ฐ€๋Šฅ์„ฑ์„ ์•”์‹œํ•œ๋‹ค.

๐ŸŽˆ ์˜์กด์„ฑ ์ „์ดโ€‹

  • ์˜์กด์„ฑ์€ ์ „์ด๋  ์ˆ˜ ์žˆ๋Š”๋ฐ, Screening์˜ ์ฝ”๋“œ๋ฅผ ์‚ดํŽด๋ณด๋ฉด Screening์ด Movie, LocalDateTime, Customer์— ์˜์กดํ•œ๋‹ค. ์˜์กด์„ฑ ์ „์ด๊ฐ€ ์˜๋ฏธํ•˜๋Š” ๊ฒƒ์€ PeriodCondition์ด Screening์— ์˜์กดํ•  ๊ฒฝ์šฐ PeriodCondition์€ Screening์ด ์˜์กดํ•˜๋Š” ๋Œ€์ƒ์— ๋Œ€ํ•ด์„œ๋„ ์ž๋™์ ์œผ๋กœ ์˜์กดํ•˜๊ฒŒ ๋œ๋‹ค ๊ฒƒ์ด๋‹ค.
  • ์˜์กด์„ฑ์€ ํ•จ๊ป˜ ๋ณ€๊ฒฝ๋  ์ˆ˜ ์žˆ๋Š” ๊ฐ€๋Šฅ์„ฑ์„ ์˜๋ฏธํ•˜๊ธฐ ๋•Œ๋ฌธ์— ๋ชจ๋“  ๊ฒฝ์šฐ์— ์˜์กด์„ฑ์ด ์ „์ด๋˜๋Š” ๊ฒƒ์€ ์•„๋‹ˆ๋‹ค. ์˜์กด์„ฑ์ด ์‹ค์ œ๋กœ ์ „์ด๋ ์ง€ ์—ฌ๋ถ€๋Š” ๋ณ€๊ฒฝ์˜ ๋ฐฉํ–ฅ๊ณผ ์บก์Šํ™”์˜ ์ •๋„์— ๋”ฐ๋ผ ๋‹ฌ๋ผ์ง„๋‹ค. ๋งŒ๊ฑ Screening์ด ์˜์กดํ•˜๊ณ  ์žˆ๋Š” ์–ด๋–ค ์š”์†Œ์˜ ๊ตฌํ˜„์ด๋‚˜ ์ธํ„ฐํŽ˜์ด์Šค๊ฐ€ ๋ณ€๊ฒฝ๋˜๋Š” ๊ฒฝ์šฐ์— ๋‚ด๋ถ€ ๊ตฌํ˜„์„ ํšจ๊ณผ์ ์œผ๋กœ ์บก์Šํ™”ํ•˜๊ณ  ์žˆ๋‹ค๋ฉด Screening์— ์˜์กดํ•˜๊ณ  ์žˆ๋Š” PeriodCondition๊นŒ์ง€๋Š” ๋ณ€๊ฒฝ์ด ์ „ํŒŒ๋˜์ง€ ์•Š์„ ๊ฒƒ์ด๋‹ค.
  • ์˜์กด์„ฑ์€ ์ „์ด๋  ์ˆ˜ ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ์˜์กด์„ฑ์˜ ์ข…๋ฅ˜๋ฅผ ์ง์ ‘ ์˜์กด์„ฑ๊ณผ ๊ฐ„์ ‘ ์˜์กด์„ฑ์œผ๋กœ ๋‚˜๋ˆ„๊ธฐ๋„ ํ•œ๋‹ค. ์ง์ ‘ ์˜์กด์„ฑ์ด๋ž€ ํ•œ ์š”์†Œ๊ฐ€ ๋‹ค๋ฅธ ์š”์†Œ์— ์ง‘์ ‘ ์˜์กดํ•˜๋Š” ๊ฒฝ์šฐ๋ฅผ ๊ฐ€๋ฆฌํ‚จ๋‹ค. (PeriodCondition์ด Screening์— ์˜์กด, ์ฝ”๋“œ์— ๋ช…์‹œ์ ์œผ๋กœ ๋“ค์–ด๋‚œ๋‹ค.) ๊ฐ„์ ‘ ์˜์กด์„ฑ์ด๋ž€ ์ง์ ‘์ ์ธ ๊ด€๊ณ„๋Š” ์กด์žฌํ•˜์ง€ ์•Š์ง€๋งŒ ์˜์กด์„ฑ ์ „์ด์— ์˜ํ•ด ์˜ํ–ฅ์ด ์ „ํŒŒ๋˜๋Š” ๊ฒฝ์šฐ๋ฅผ ๊ฐ€๋ฆฌํ‚จ๋‹ค. (์ฝ”๋“œ ์•ˆ์— ๋ช…์‹œ์ ์œผ๋กœ ๋“œ๋Ÿฌ๋‚˜์ง€ ์•Š๋Š๋‹ค.)

๐ŸŽˆ ๋Ÿฐํƒ€์ž„ ์˜์กด์„ฑ๊ณผ ์ปดํŒŒ์ผํƒ€์ž„ ์˜์กด์„ฑโ€‹

  • ๋จผ์ € ๋Ÿฐํƒ€์ž„๊ณผ ์ปดํŒŒ์ผํƒ€์ž„์˜ ์˜๋ฏธ๋ฅผ ์ดํ•ดํ•ด์•ผ ํ•œ๋‹ค.
  • ๋Ÿฐํƒ€์ž„์€ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์‹คํ–‰๋˜๋Š” ์‹œ์ ์„ ๊ฐ€๋ฆฌํ‚จ๋‹ค.
  • ์ปดํŒŒ์ผํƒ€์ž„์€ ์ผ๋ฐ˜์ ์œผ๋กœ ์ž‘์„ฑ๋œ ์ฝ”๋“œ๋ฅผ ์ปดํŒŒ์ผํ•˜๋Š” ์‹œ์ ์„ ๊ฐ€๋ฆฌํ‚ค์ง€๋งŒ ๋ฌธ๋งฅ์— ๋”ฐ๋ผ์„œ๋Š” ์ฝ”๋“œ ๊ทธ ์ž์ฒด๋ฅผ ๊ฐ€๋ฆฌํ‚ค๊ธฐ๋„ ํ•œ๋‹ค.
  • ์ปดํŒŒ์ผํƒ€์ž„ ์˜์กด์„ฑ์ด๋ผ๋Š” ์šฉ์–ด๊ฐ€ ์ค‘์š”ํ•˜๊ฒŒ ์ƒ๊ฐํ•˜๋Š” ๊ฒƒ์€ ์‹œ๊ฐ„์ด ์•„๋‹ˆ๋ผ ์šฐ๋ฆฌ๊ฐ€ ์ž‘์„ฑํ•œ ์ฝ”๋“œ์˜ ๊ตฌ์กฐ์ด๋‹ค. ๋˜ํ•œ ๋™์  ํƒ€์ž… ์–ธ์–ด์˜ ๊ฒฝ์šฐ์—๋Š” ์ปดํŒŒ์ผํƒ€์ž„์ด ์กด์žฌํ•˜์ง€ ์•Š๊ธฐ ๋•Œ๋ฌธ์— ์ปดํŒŒ์ผํƒ€์ž„ ์˜์กด์„ฑ์ด๋ผ๋Š” ์šฉ์–ด๋ฅผ ์‹ค์ œ๋กœ ์ปดํŒŒ์ผ์ด ์ˆ˜ํ–‰๋˜๋Š” ์‹œ์ ์œผ๋กœ ์ดํ•ดํ•˜๋ฉด ์˜๋ฏธ๊ฐ€ ๋ชจํ˜ธํ•ด์งˆ ์ˆ˜ ์žˆ๋‹ค.
  • ๊ฐ์ฒด์ง€ํ–ฅ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์—์„œ ๋Ÿฐํƒ€์ž„์˜ ์ฃผ์ธ๊ณต์€ ๊ฐ์ฒด๋‹ค. ๋”ฐ๋ผ์„œ ๋Ÿฐํƒ€์ž„ ์˜์กด์„ฑ์ด ๋‹ค๋ฃจ๋Š” ์ฃผ์ œ๋Š” ๊ฐ์ฒด ์‚ฌ์ด์˜ ์˜์กด์„ฑ์ด๋‹ค. ๋ฐ˜๋ฉด ์ฝ”๋“œ ๊ณผ์ ์—์„œ ์ฃผ์ธ๊ณต์€ ํด๋ž˜์Šค๋‹ค. ๋”ฐ๋ผ์„œ ์ปดํŒŒ์ผํƒ€์ž„ ์˜์กด์„ฑ์ด ๋‹ค๋ฃจ๋Š” ์ฃผ์ œ๋Š” ํด๋ž˜์Šค ์‚ฌ์ด์˜ ์˜์กด์„ฑ์ด๋‹ค.
  • ์ด์ „์˜ ์˜ํ™” ์˜ˆ๋งค ์‹œ์Šคํ…œ์—์„œ Movie๋Š” ๋น„์œจ ํ• ์ธ ์ •์ฑ…๊ณผ ๊ธˆ์•ก ํ• ์ธ ์ •์ฑ… ๋ชจ๋‘๋ฅผ ์ ์šฉํ•˜๊ฒŒ ์„ค๊ณ„ํ–ˆ๋‹ค. ์ด๋•Œ Movie๋Š” ์ถ”์ƒ ํด๋ž˜์Šค์ธ DiscountPolicy์— ์˜์กดํ•˜๋„๋ก ํด๋ž˜์Šค ๊ด€๊ณ„๋ฅผ ์„ค๊ณ„ํ–ˆ๋‹ค. DiscountPolicy๋Š” AmountDiscountPolicy์™€ PercentDiscountPolicy๊ฐ€ ์ƒ์†๋ฐ›์•˜๋‹ค.
  • ์—ฌ๊ธฐ์„œ ์ค‘์š”ํ•œ ๊ฒƒ์€ Movie๋Š” AmountDiscountPolicy๋‚˜ PercentDiscountPolicy ํด๋ž˜์Šค๋กœ ํ–ฅํ•˜๋Š” ์–ด๋–ค ์˜์กด์„ฑ๋„ ์กด์žฌํ•˜์ง€ ์•Š๋Š”๋‹ค๋Š” ๊ฒƒ์ด๋‹ค. ์˜ค์ง ์ถ”์ƒ ํด๋ž˜์Šค์ธ DiscountPolicy ํด๋ž˜์Šค์—๋งŒ ์˜์กดํ•œ๋‹ค.
  • ํ•˜์ง€๋งŒ ๋Ÿฐํƒ€์ž„ ์˜์กด์„ฑ์„ ์‚ดํŽด๋ณด๋ฉด ๊ธˆ์•ก ํ• ์ธ ์ •์ฑ…์„ ์ ์šฉํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” AmountDiscountPolicy์˜ ์ธ์Šคํ„ด์Šค์™€ ํ˜‘๋ ฅํ•ด์•ผํ•˜๊ณ  ๋น„์œจ ํ• ์ธ ์ •์ฑ…์„ ์ ์šฉํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” PercentDiscountPolicy์˜ ์ธ์Šคํ„ด์Šค์™€ ํ˜‘๋ ฅํ•ด์•ผ ํ•œ๋‹ค.
  • ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•˜๋Š” ์‹œ์ ์˜ Movie ํด๋ž˜์Šค๋Š” ์ด ๋‘ ํด๋ž˜์Šค์˜ ์กด์žฌ์— ๋Œ€ํ•ด ์ „ํ˜€ ์•Œ์ง€ ๋ชปํ•˜์ง€๋งŒ ์‹คํ–‰ ์‹œ์ ์˜ Movie ์ธ์Šคํ„ด์Šค๋Š” AmountDiscountPolicy ์ธ์Šคํ„ด์Šค์™€ PercentDiscountPolicy ์ธ์Šคํ„ด์Šค์™€ ํ˜‘๋ ฅํ•  ์ˆ˜ ์žˆ์–ด์•ผ ํ•œ๋‹ค.
  • ์ด ๋‘ ํด๋ž˜์Šค์˜ ์ธ์Šคํ„ด์Šค์™€ ํ•จ๊ป˜ ํ˜‘๋ ฅํ•  ์ˆ˜ ์ด์Ž„ ๋งŒ๋“œ๋Š” ๋” ๋‚˜์€ ๋ฐฉ๋ฒ•์€ Movie๊ฐ€ ๋‘ ํด๋ž˜์Šค ์ค‘ ์–ด๋–ค ๊ฒƒ๋„ ์•Œ์ง€ ๋ชปํ•˜๊ฒŒ ๋งŒ๋“œ๋Š” ๊ฒƒ์œผ๋กœ DiscountPolicy๋ผ๋Š” ์ถ”์ƒ ํด๋ž˜์Šค์— ์˜์กดํ•˜๋„๋ก ๋งŒ๋“ค๊ณ  ์ด ์ปดํŒŒ์ผํƒ€์ž„ ์˜์กด์„ฑ์„ ์‹คํ–‰ ์‹œ์— PercentDiscountPolicy ์ธ์Šคํ„ด์Šค๋‚˜ AmountDiscountPolicy ์ธ์Šคํ„ด์Šค์— ๋Œ€ํ•œ ๋Ÿฐํƒ€์ž„ ์˜์กด์„ฑ์œผ๋กœ ๋Œ€์ฒดํ•ด์•ผ ํ•œ๋‹ค.
  • ์–ด๋–ค ํด๋ž˜์Šค์˜ ์ธ์Šคํ„ด์Šค๊ฐ€ ๋‹ค์–‘ํ•œ ํด๋ž˜์Šค์˜ ์ธ์Šคํ„ด์Šค์™€ ํ˜‘๋ ฅํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” ํ˜‘๋ ฅํ•  ์ธ์Šคํ„ด์Šค์˜ ๊ตฌ์ฒด์ ์ธ ํด๋ž˜์Šค๋ฅผ ์•Œ์•„์„œ๋Š” ์•ˆ ๋œ๋‹ค. ์‹ค์ œ๋กœ ํ˜‘๋ ฅํ•  ๊ฐ์ฒด๊ฐ€ ์–ด๋–ค ๊ฒƒ์ธ์ง€๋Š” ๋Ÿฐํƒ€์ž„์— ํ•ด๊ฒฐํ•ด์•ผ ํ•œ๋‹ค.
  • ์ปดํŒŒ์ผํƒ€์ž… ๊ตฌ์กฐ์™€ ๋Ÿฐํƒ€์ž„ ๊ตฌ์กฐ ์‚ฌ์ด์˜ ๊ฑฐ๋ฆฌ๊ฐ€ ๋ฉ€๋ฉด ๋ฉ€์ˆ˜๋ก ์„ค๊ณ„๊ฐ€ ์œ ์—ฐํ•ด์ง€๊ณ  ์žฌ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•ด์ง„๋‹ค.

๐ŸŽˆ ์ปจํ…์ŠคํŠธ ๋…๋ฆฝ์„ฑโ€‹

  • ํด๋ž˜์Šค๊ฐ€ ํŠน์ •ํ•œ ๋ฌธ๋งฅ์— ๊ฐ•ํ•˜๊ฒŒ ๊ฒฐํ•ฉ๋ ์ˆ˜๋ก ๋‹ค๋ฅธ ๋ฌธ๋งฅ์—์„œ ์‚ฌ์šฉํ•˜๊ธฐ๋Š” ๋” ์–ด๋ ค์›Œ์ง„๋‹ค. ํด๋ž˜์Šค๊ฐ€ ์‚ฌ์šฉ๋  ํŠน์ •ํ•œ ๋ฌธ๋งฅ์— ๋Œ€ํ•ด ์ตœ์†Œํ•œ์˜ ๊ฐ€์ •๋งŒ์œผ๋กœ ์ด๋ค„์ ธ ์žˆ๋‹ค๋ฉด ๋‹ค๋ฅธ ๋ฌธ๋งฅ์—์„œ ์žฌ์‚ฌ์šฉํ•˜๊ธฐ๊ฐ€ ๋” ์ˆ˜์›”ํ•ด์ง„๋‹ค. ์ด๋ฅผ ์ปจํ…์ŠคํŠธ ๋…๋ฆฝ์„ฑ์ด๋ผ๊ณ  ๋ถ€๋ฅธ๋‹ค.
  • ์„ค๊ณ„๊ฐ€ ์œ ์—ฐํ•ด์ง€๊ธฐ ์œ„ํ•ด์„œ๋Š” ๊ฐ€๋Šฅํ•œ ํ•œ ์ž์‹ ์ด ์‹คํ–‰๋  ์ปจํ…์ŠคํŠธ์— ๋Œ€ํ•œ ๊ตฌ์ฒด์ ์ธ ์ •๋ณด๋ฅผ ์ตœ๋Œ€ํ•œ ์ ๊ฒŒ ์•Œ์•„์•ผ ํ•œ๋‹ค.

๐ŸŽˆ ์˜์กด์„ฑ ํ•ด๊ฒฐํ•˜๊ธฐโ€‹

  • ์ปดํŒŒ์ผํƒ€์ž„ ์˜์กด์„ฑ์€ ๊ตฌ์ฒด์ ์ธ ๋Ÿฐํƒ€์ž„ ์˜์กด์„ฑ์œผ๋กœ ๋Œ€์ฒด๋ผ์•ผ ํ•œ๋‹ค.
  • ์ปดํŒŒ์ผํƒ€์ž„ ์˜์กด์„ฑ์„ ์‹คํ–‰ ์ปจํ…์ŠคํŠธ์— ๋งž๋Š” ์ ์ ˆํ•œ ๋Ÿฐํƒ€์ž„ ์˜์กด์„ฑ์œผ๋กœ ๊ต์ฒดํ•˜๋Š” ๊ฒƒ์„ ์˜์กด์„ฑ ํ•ด๊ฒฐ์ด๋ผ๊ณ  ๋ถ€๋ฅธ๋‹ค. ์˜์กด์„œ์„ ํ•ด๊ฒฐํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” ์ผ๋ฐ˜์ ์œผ๋กœ ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์„ธ ๊ฐ€์ง€ ๋ฐฉ๋ฒ•์„ ์‚ฌ์šฉํ•œ๋‹ค.
    • ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•˜๋Š” ์‹œ์ ์— ์ƒ์„ฑ์ž๋ฅผ ํ†ตํ•ด ์˜์กด์„ฑ ํ•ด๊ฒฐ
    • ๊ฐ์ฒด ์ƒ์„ฑ ํ›„ setter ๋ฉ”์„œ๋“œ๋ฅผ ํ†ตํ•ด ์˜์กด์„ฑ ํ•ด๊ฒฐ
    • ๋ฉ”์„œ๋“œ ์‹คํ–‰ ์‹œ ์ธ์ž๋ฅผ ์ด์šฉํ•˜์—ฌ ์˜์กด์„ฑ ํ•ด๊ฒฐ
  • ๋‹ค์Œ๊ณผ ๊ฐ™์ด Movie ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•  ๋•Œ AmountDiscountPolicy๋‚˜ PercentDiscountPolicy์˜ ์ธ์Šคํ„ด์Šค๋ฅผ Movie์˜ ์ƒ์„ฑ์ž์— ์ธ์ž๋กœ ์ „๋‹ฌํ•˜๋ฉด ๋œ๋‹ค.
Movie avatar = new Movie("์•„๋ฐ”ํƒ€",
Duration.ofMinutes(120),
Money.wons(10000),
new AmountDiscountPolicy(...)
);

Movie starWars = new Movie("์Šคํƒ€์›Œ์ฆˆ",
Duration.ofMinutes(180),
Money.wons(11000),
new PercentDiscountPolicy(...)
);
  • ์ด ๊ฒฝ์šฐ Movie๋Š” ์ƒ์„ฑ์ž๋ฅผ ์ •์˜ํ•œ๋‹ค.
public class Movie {
public Movie(String title, Duration runningTime, Money fee, DiscountPolicy discountPolicy) {
// ...
this.discountPolicy = discountPolicy;
}
}
  • Movie ์ธ์Šคํ„ด์Šค๋ฅผ ์ƒ์„ฑํ•œ ํ›„์— ๋ฉ”์„œ๋“œ๋ฅผ ์ด์šฉํ•ด ์˜์กด์„ฑ์„ ํ•ด๊ฒฐํ•  ์ˆ˜๋„ ์žˆ๋‹ค.
Movie avatar = new Movie(...);
avatar.setDiscountPolicy(new AmountDiscountPolicy(...));
  • ์ด ๊ฒฝ์šฐ setter ๋ฉ”์„œ๋“œ๋ฅผ ์ œ๊ณตํ•ด์•ผ ํ•œ๋‹ค.
public class Movie {
public void setDiscountPolicy (DiscountPolicy discountPolicy) {
this.discountPolicy = discountPolicy;
}
}
  • setter ๋ฉ”์„œ๋“œ๋ฅผ ์ด์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•์€ ์‹คํ–‰ ์‹œ์ ์— ์˜์กด ๋Œ€์ƒ์ด ๋ณ€๊ฒฝํ•  ์ˆ˜ ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ์„ค๊ณ„์— ์ข€ ๋” ์œ ์—ฐํ•˜๊ฒŒ ๋งŒ๋“ค ์ˆ˜ ์žˆ๋‹ค. ๋‹จ์ ์€ ๊ฐ์ฒด๊ฐ€ ์ƒ์„ฑ๋œ ํ›„์— ํ˜‘๋ ฅ์— ํ•„์š”ํ•œ ์˜์กด ๋Œ€์ƒ์„ ์„ค์ €ํ•˜๊ธฐ ๋•Œ๋ฌธ์— ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•˜๊ณ  ์˜์กด ๋Œ€์ƒ์„ ์„ค์ •ํ•˜๊ธฐ ์ „๊นŒ์ง€๋Š” ๊ฐ์ฒด์˜ ์ƒํƒœ๊ฐ€ ๋ถˆ์™„์ „ํ•  ์ˆ˜ ์žˆ๋‹ค๋Š” ์ ์ด๋‹ค.
  • ๋•Œ๋ฌธ์— ๋” ์ข‹์€ ๋ฐฉ๋ฒ•์€ ์ƒ์„ฑ์ž ๋ฐฉ์‹๊ณผ setter ๋ฐฉ์‹์„ ํ˜ผํ•ฉํ•˜๋Š” ๊ฒƒ์ด๋‹ค. ํ•ญ์ƒ ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•  ๋•Œ ์˜์กด์„ฑ์„ ํ•ด๊ฒฐํ•ด์„œ ์™„์ „ํ•œ ์ƒํƒœ์˜ ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•œ ํ›„, ํ•„์š”์— ๋”ฐ๋ผ setter ๋ฉ”์„œ๋“œ๋ฅผ ์ด์šฉํ•ด ์˜์กด ๋Œ€์ƒ์„ ๋ณ€๊ฒฝํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•  ์ˆ˜ ์žˆ๋‹ค.
Movie avatar = new Movie("์•„๋ฐ”ํƒ€",
Duration.ofMinutes(120),
Money.wons(10000),
new AmountDiscountPolicy(...)
);

// ...

avatar.setDiscountPolicy(new AmountDiscountPolicy(...));
  • Movie๊ฐ€ ํ•ญ์ƒ ํ• ์ธ ์ •์ฑ…์„ ์•Œ ํ•„์š”๊นŒ์ง€๋Š” ์—†๊ณ  ๊ฐ€๊ฒฉ์„ ๊ณ„์‚ฐํ•  ๋•Œ๋งŒ ์ผ์‹œ์ ์œผ๋กœ ์•Œ์•„๋„ ๋ฌด๋ฐ”ํ•˜๋‹ค๋ฉด ๋ฉ”์„œ๋“œ์˜ ์ธ์ž๋ฅผ ์ด์šฉํ•ด ์˜์กด์„ฑ์„ ํ•ด๊ฒฐํ•  ์ˆ˜๋„ ์žˆ๋‹ค.
public class Movie {
public Money calculateMovieFee(Screening screening, DiscountPolicy discountPolicy) {
return fee.minus(discountPolicy.calculateDiscountAmount(screening));
}
}

๐Ÿ“š ์œ ์—ฐํ•œ ์„ค๊ณ„โ€‹

๐ŸŽˆ ์˜์กด์„ฑ๊ณผ ๊ฒฐํ•ฉ๋„โ€‹

  • ๊ฐ์ฒด๋“ค์ด ํ˜‘๋ ฅํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” ์„œ๋กœ์˜ ์กด์žฌ์™€ ์ˆ˜ํ–‰ ๊ฐ€๋Šฅํ•œ ์ฑ…์ž„์„ ์•Œ์•„์•ผ ํ•œ๋‹ค. ์ด๋Ÿฐ ์ง€์‹๋“ค์ด ๊ฐ์ฒด ์‚ฌ์ด์˜ ์˜์กด์„ฑ์„ ๋‚ณ๋Š”๋‹ค. ๋”ฐ๋ผ์„œ ๋ชจ๋“  ์˜์กด์„ฑ์ด ๋‚˜์œ ๊ฒƒ์€ ์•„๋‹ˆ๋‹ค. ํ•˜์ง€๋งŒ ์˜์กด์„ฑ์ด ๊ณผํ•˜๋ฉด ๋ฌธ์ œ๊ฐ€ ๋  ์ˆ˜ ์žˆ๋‹ค.
  • ์˜์กด์„ฑ์€ ํ˜‘๋ ฅ์„ ์œ„ํ•ด ๋ฐ˜๋“œ์‹œ ํ•„์š”ํ•œ ๊ฒƒ์ด๋‹ค. ๋‹จ์ง€ ๋ฐ”๋žŒ์งํ•˜์ง€ ๋ชปํ•œ ์˜์กด์„ฑ์ด ๋ฌธ์ œ์ผ ๋ฟ์ด๋‹ค.
  • ์—ฌ๊ธฐ์„œ ๋ฐ”๋žŒ์งํ•œ ์˜์กด์„ฑ์€ ์žฌ์‚ฌ์šฉ์„ฑ๊ณผ ๊ด€๋ ค์ด ์žˆ๋Š”๋ฐ ์–ด๋–ค ์˜์กด์„ฑ์ด ๋‹ค์–‘ํ•œ ํ™˜๊ฒฝ์—์„œ ํด๋ž˜์Šค๋ฅผ ์žฌ์‚ฌ์šฉํ•  ์ˆ˜ ์—†๋„๋ก ์ œํ•œํ•œ๋‹ค๋ฉด ๊ทธ ์˜์กด์„ฑ์€ ๋ฐ”๋žŒ์งํ•˜์ง€ ๋ชปํ•œ ๊ฒƒ์ด๋‹ค. ๋‹ค์‹œ ๋งํ•ด ์ปจํ…์ŠคํŠธ์— ๋…๋ฆฝ์ ์ธ ์˜์กด์„ฑ์€ ๋ฐ”๋žŒ์งํ•œ ์˜์กด์„ฑ์ด๊ณ  ํŠน์ •ํ•œ ์ปจํ…์ŠคํŠธ์— ๊ฐ•ํ•˜๊ฒŒ ๊ฒฐํ•ฉ๋œ ์˜์กด์„ฑ์€ ๋ฐ”๋žŒ์งํ•˜์ง€ ์•Š์€ ์˜์กด์„ฑ์ด๋‹ค.
  • ๋‹ค๋ฅธ ํ™˜๊ฒฝ์—์„œ ์žฌ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•ด ๋‚ด๋ถ€ ๊ตฌํ˜„์„ ๋ณ€๊ฒฝํ•˜๊ฒŒ ๋งŒ๋“œ๋Š” ๋ชจ๋“  ์˜์กด์„ฑ์€ ๋ฐ”๋žŒ์งํ•˜์ง€ ์•Š์€ ์˜์กด์„ฑ์ด๋‹ค. ๋ฐ”๋žŒ์งํ•œ ์˜์กด์„ฑ์ด๋ž€ ์ปจํ…์ŠคํŠธ์— ๋…๋ฆฝ์ ์ธ ์˜์กด์„ฑ์„ ์˜๋ฏธํ•˜๋ฉฐ ๋‹ค์–‘ํ•œ ํ™˜๊ฒฝ์—์„œ ์žฌ์‚ฌ์šฉ๋  ์ˆ˜ ์žˆ๋Š” ๊ฐ€๋Šฅ์„ฑ์„ ์—ด์–ด๋†“๋Š” ์˜์กด์„ฑ์„ ์˜๋ฏธํ•œ๋‹ค.
  • ์–ด๋–ค ๋‘ ์š”์†Œ ์‚ฌ์ด์— ์กด์žฌํ•˜๋Š” ์˜์กด์„ฑ์ด ๋ฐ”๋žŒ์งํ•  ๋•Œ ๋‘ ์š”์†Œ๊ฐ€ ๋Š์Šจํ•œ ๊ฒฐํ•ฉ๋„ ๋˜๋Š” ์•ฝํ•œ ๊ฒฐํ•ฉ๋„๋ฅผ ๊ฐ€์ง„๋‹ค๊ณ  ๋งํ•œ๋‹ค. ๋ฐ˜๋Œ€๋กœ ๋‘ ์š”์†Œ ์‚ฌ์ด์˜ ์˜์กด์„ฑ์ด ๋ฐ”๋žŒ์งํ•˜์ง€ ๋ชปํ•  ๋•Œ ๋‹จ๋‹จํ•œ ๊ฒฐํ•ฉ๋„ ๋˜๋Š” ๊ฐ•ํ•œ ๊ฒฐํ•ฉ๋„๋ฅผ ๊ฐ€์ง„๋‹ค๊ณ  ๋งํ•œ๋‹ค.

๐ŸŽˆ ์ง€์‹์ด ๊ฒฐํ•ฉ์„ ๋‚ณ๋Š”๋‹ค.โ€‹

  • ๊ฒฐํ•ฉ๋„์˜ ์ •๋„๋Š” ํ•œ ์š”์†Œ๊ฐ€ ์ž์‹ ์ด ์˜์กดํ•˜๊ณ  ์žˆ๋Š” ๋‹ค๋ฅธ ์š”์†Œ์— ๋Œ€ํ•ด ์•Œ๊ณ  ์žˆ๋Š” ์ •๋ณด์˜ ์–‘์œผ๋กœ ๊ฒฐ์ •๋œ๋‹ค. ๋งŒ์•ฝ ๋งŽ์€ ์ •๋ณด๋ฅผ ์•Œ๊ณ  ์žˆ์œผ๋ฉด ๊ฐ•ํ•˜๊ฒŒ ๊ฒฐํ•ฉ๋˜๊ณ  ๋ฐ˜๋Œ€๋กœ ์ ์€ ์ •๋ณด๋ฅผ ์•Œ๊ณ  ์žˆ์œผ๋ฉด ์•ฝํ•˜๊ฒŒ ๊ฒฐํ•ฉ๋œ๋‹ค.
  • ์„œ๋กœ์— ๋Œ€ํ•ด ์•Œ๊ณ  ์žˆ๋Š” ์ง€์‹์˜ ์–‘์ด ๊ฒฐํ•ฉ๋„๋ฅผ ๊ฒฐ์ •ํ•œ๋‹ค.
  • ๋” ๋งŽ์ด ์•Œ๊ณ  ์žˆ๋‹ค๋Š” ๊ฒƒ์€ ๋” ์ ์€ ์ปจํ…์ŠคํŠธ์—์„œ ์žฌ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•˜๋‹ค๋Š” ๊ฒƒ์„ ์˜๋ฏธํ•œ๋‹ค. ๊ฒฐํ•ฉ๋„๋ฅผ ๋Š์Šจํ•˜๊ฒŒ ์œ ์ง€ํ•˜๋ ค๋ฉด ํ˜‘๋ ฅํ•˜๋Š” ๋Œ€์ƒ์— ๋Œ€ํ•ด ๋” ์ ๊ฒŒ ์•Œ์•„์•ผ ํ•œ๋‹ค. ๋˜ํ•œ, ํ˜‘๋ ฅํ•˜๋Š” ๋Œ€์ƒ์— ๋Œ€ํ•ด ํ•„์š”ํ•œ ์ •๋ณด ์™ธ์—๋Š” ์ตœ๋Œ€ํ•œ ๊ฐ์ถ”๋Š” ๊ฒƒ์ด ์ค‘์š”ํ•˜๋‹ค.
  • ๊ฐ€์žฅ ํšจ๊ณผ์ ์ธ ๋ฐฉ๋ฒ•์€ ์ถ”์ƒํ™”๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ด๋‹ค.

๐ŸŽˆ ์ถ”์ƒํ™”์— ์˜์กดํ•˜๋ผโ€‹

  • ์ถ”์ƒํ™”๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ํ˜„์žฌ ๋‹ค๋ฃจ๊ฐ€ ์žˆ๋Š” ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•˜๋Š” ๋ฐ ๋ถˆํ•„์š”ํ•œ ์ •๋ณด๋ฅผ ๊ฐ์ถœ ์ˆ˜ ์žˆ๋‹ค. ๋”ฐ๋ผ์„œ ๋Œ€์ƒ์— ๋Œ€ํ•ด ์•Œ์•„์•ผ ํ•˜๋Š” ์ง€์‹์˜ ์–‘์„ ์ค„์ผ ์ˆ˜ ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ๊ฒฐํ•ฉ๋„๋ฅผ ๋Š์Šจํ•˜๊ฒŒ ์œ ์ง€ํ•  ์ˆ˜ ์žˆ๋‹ค.
  • ์ผ๋ฐ˜์ ์œผ๋กœ ์ถ”์ƒํ™”์™€ ๊ฒฐํ•ฉ๋„์˜ ๊ด€์ ์—์„œ ์˜์กด ๋Œ€์ƒ์„ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ๊ตฌ๋ถ„ํ•˜๋Š” ๊ฒƒ์ด ์œ ์šฉํ•˜๊ณ  ๋ชฉ๋ก์—์„œ ์•„๋ž˜์ชฝ์œผ๋กœ ๊ฐˆ์ˆ˜๋ก ํด๋ผ์ด์–ธํŠธ๊ฐ€ ์•Œ์•„์•ผ ํ•˜๋Š” ์ง€์‹์˜ ์–‘์ด ์ ์–ด์ง€๊ธฐ ๋•Œ๋ฌธ์— ๊ฒฐํ•ฉ๋„๊ฐ€ ๋Š์Šจํ•ด์ง„๋‹ค.
    • ๊ตฌ์ฒด ํด๋ž˜์Šค ์˜์กด์„ฑ
    • ์ถ”์ƒ ํด๋ž˜์Šค ์˜์กด์„ฑ
    • ์ธํ„ฐํŽ˜์ด์Šค ์˜์กด์„ฑ
  • ์—ฌ๊ธฐ์„œ ์ค‘์š”ํ•œ ๊ฒƒ์€ ์‹คํ–‰ ์ปจํ…์ŠคํŠธ์— ๋Œ€ํ•ด ์•Œ์•„์•ผ ํ•˜๋Š” ์ •๋ณด๋ฅผ ์ค„์ผ์ˆ˜๋ก ๊ฒฐํ•ฉ๋„๊ฐ€ ๋‚ฎ์•„์ง„๋‹ค๋Š” ๊ฒƒ์ด๋‹ค.

๐ŸŽˆ ๋ช…์‹œ์ ์ธ ์˜์กด์„ฑโ€‹

  • ์•„๋ž˜ ์ฝ”๋“œ๋Š” ํ•œ ๊ฐ€์ง€ ์‹ค์ˆ˜๋กœ ์ธํ•ด ๊ฒฐํ•ฉ๋„๊ฐ€ ๋ถˆํ•„์š”ํ•˜๊ฒŒ ๋†’์•„์กŒ๋‹ค.
public class Movie {
// ...
private DiscountPolicy discountPolicy;

public Movie(String title, Duration runningTime, Money fee) {
// ...
this.discountPolicy = new AmountDiscountPolicy(...);
}
}
  • discountPolicy๋Š” DiscountPolicy ํƒ€์ž…์œผ๋กœ ์„ ์–ธ๋ผ ์žˆ์ง€๋งŒ ์ƒ์„ฑ์ž์—์„œ ๊ตฌ์ฒด ํด๋ž˜์Šค์ธ AmountDiscountPolicy์˜ ์ธ์Šคํ„ด์Šค๊ฐ€ ์ง์ ‘ ์ƒ์„ฑํ•ด์„œ ๋Œ€์ž…ํ•˜๊ณ  ์žˆ๋‹ค. ๋”ฐ๋ผ์„œ Movie๋Š” ์ถ”์ƒ ํด๋ž˜์Šค์ธ DiscountPolicy ๋ฟ๋งŒ ์•„๋‹ˆ๋ผ ๊ตฌ์ฒด ํด๋ž˜์Šค์ธ AmountDiscountPolicy์—๋„ ์˜์กดํ•˜๊ฒŒ ๋œ๋‹ค.
  • ํ•ด๊ฒฐํ•˜๊ธฐ ์œ„ํ•ด์„œ ํด๋ž˜์Šค ์•ˆ์—์„œ ๊ตฌ์ฒด ํด๋ž˜์Šค์— ๋Œ€ํ•œ ๋ชจ๋“  ์˜์กด์„ฑ์„ ์ œ๊ฑฐํ•ด์•ผ๋งŒ ํ•œ๋‹ค.
  • ๋‹ค์Œ์€ ์ƒ์„ฑ์ž๋ฅผ ์‚ฌ์šฉํ•ด ์˜์กด์„ฑ์„ ํ•ด๊ฒฐํ•˜๋Š” ๊ฒฝ์šฐ๋ฅผ ๋‚˜ํƒ€๋‚ธ ๊ฒƒ์ด๋‹ค.
public class Movie {
// ...
private DiscountPolicy discountPolicy;

public Movie(String title, Duration runningTime, Money fee, DiscountPolicy discountPolicy) {
// ...
this.discountPolicy = discountPolicy;
}
}
  • ์ƒ์„ฑ์ž์˜ ์ธ์ž๋กœ DiscountPolicy์˜ ์ž์‹ ํด๋ž˜์Šค ์ค‘ ์–ด๋–ค ๊ฒƒ์ด๋ผ๋„ ์ „๋‹ฌํ•  ์ˆ˜ ์žˆ๋‹ค. ๋”ฐ๋ผ์„œ ๋Ÿฐํƒ€์ž„์— AmountDiscountPolicy์˜ ์ธ์Šคํ„ด์Šค๋‚˜ PercentDiscountPolicy์˜ ์ธ์Šคํ„ด์Šค๋ฅผ ์„ ํƒ์ ์œผ๋กœ ์ „๋‹ฌํ•  ์ˆ˜ ์žˆ๋‹ค.
  • ์˜์กด์„ฑ์˜ ๋Œ€์ƒ์œผ๋กœ ์ƒ์„ฑ์ž์˜ ์ธ์ž๋กœ ์ „๋‹ฌ๋ฐ›๋Š” ๋ฐฉ๋ฒ•๊ณผ ์ƒ์„ฑ์ž ์•ˆ์—์„œ ์ง์ ‘ ์ƒ์„ฑํ•˜๋Š” ๋ฐฉ๋ฒ• ์‚ฌ์ด์˜ ๊ฐ€์žฅ ํฐ ์ฐจ์ด์ ์€ ํผ๋ธ”๋ฆญ ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ํ†ตํ•ด ํ• ์ธ ์ •์ฑ…์„ ์„ค์ •ํ•  ์ˆ˜ ์žˆ๋Š” ๋ฐฉ๋ฒ•์„ ์ œ๊ณตํ•˜๋Š”์ง€ ์—ฌ๋ถ€๋‹ค. ์ƒ์„ฑ์ž์˜ ์ธ์ž๋กœ ์„ ์–ธํ•˜๋Š” ๋ฐฉ๋ฒ•์€ Movie๊ฐ€ DiscountPolicy์— ์˜์กดํ•œ๋‹ค๋Š” ์‚ฌ์‹ค์„ Movie์˜ ํผ๋ธ”๋ฆญ ์ธํ„ฐํŽ˜์ด์Šค์— ๋“œ๋Ÿฌ๋‚ด๋Š” ๊ฒƒ์ด๋‹ค. ์ด๋ฅผ ๋ช…์‹œ์ ์ธ ์˜์กด์„ฑ์ด๋ผ๊ณ  ๋ถ€๋ฅธ๋‹ค.
  • ๋ฐ˜๋ฉด Movie๋‚ด๋ถ€์—์„œ AmountDiscountPolicy์˜ ์ธ์Šคํ„ด์Šค๋ฅผ ์ง์ ‘ ์ƒ์„ฑํ•˜๋Š” ๋ฐฉ์‹์€ Movie๊ฐ€ DiscountPolicy์— ์˜์กดํ•œ๋‹ค๋Š” ์‚ฌ์‹ค์„ ๊ฐ์ถ˜๋‹ค. ๋‹ค์‹œ ๋งํ•ด ์˜์กด์„ฑ์ด ํผ๋ธ”๋ฆฐ ์ธํ„ฐํŽ˜์ด์Šค์— ํ‘œํ˜„๋˜์ง€ ์•Š๋Š”๋‹ค. ์ด๋ฅผ ์ˆจ๊ฒจ์ง„ ์˜์กด์„ฑ์ด๋ผ๊ณ  ๋ถ€๋ฅธ๋‹ค. ์˜์กด์„ฑ์ด ๋ช…์‹œ์ ์ด์ง€ ์•Š์œผ๋ฉด ์˜์กด์„ฑ์„ ํŒŒ์•…ํ•˜๊ธฐ ์œ„ํ•ด ๋ฐฐ๊ตฌ ๊ตฌํ˜„์„ ์ง์ ‘ ์‚ดํŽด๋ณผ ์ˆ˜๋ฐ–์— ์—†๋‹ค.
  • ์˜์กด์„ฑ์„ ๋ช…์‹œ์ ์œผ๋กœ ๋“œ๋Ÿฌ๋‚ด๋ฉด ์ฝ”๋“œ๋ฅผ ์ง์ ‘ ์ˆ˜์ •ํ•ด์•ผ ํ•˜๋Š” ์œ„ํ—˜์„ ํ”ผํ•  ์ˆ˜ ์žˆ๋‹ค. ์‹คํ–‰ ์ปจํ…์ŠคํŠธ์— ์ ์ ˆํ•œ ์˜์กด์„ฑ์„ ์„ ํƒํ•  ์ˆ˜ ์žˆ๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค.
  • ๋ช…์‹œ์ ์ธ ์˜์กด์„ฑ์„ ์‚ฌ์šฉํ•ด์•ผ๋งŒ ํผ๋ธ”๋ฆญ ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ํ†ตํ•ด ์ปดํŒŒ์ผํƒ€์ž„ ์˜์กด์„ฑ์„ ์ ์ ˆํ•œ ๋Ÿฐํƒ€์ž„ ์˜์กด์„ฑ์œผ๋กœ ๊ต์ฒดํ•  ์ˆ˜ ์žˆ๋‹ค.

๐ŸŽˆ new๋Š” ํ•ด๋กญ๋‹คโ€‹

  • new๋ฅผ ์ž˜๋ชป ์‚ฌ์šฉํ•˜๋ฉด ํด๋ž˜์Šค ์‚ฌ์ด์˜ ๊ฒฐํ•ฉ๋„๊ฐ€ ๊ทน๋‹จ์ ์œผ๋กœ ๋†’์•„์ง„๋‹ค. ๊ฒฐํ•ฉ๋„ ์ธก๋ฉด์—์„œ new๊ฐ€ ํ•ด๋กœ์šด ์ด์œ ๋Š” ํฌ๊ฒŒ ๋‘ ๊ฐ€์ง€์ด๋‹ค.
    • new ์—ฐ์‚ฐ์ž๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” ๊ตฌ์ฒด ํด๋ž˜์Šค์˜ ์ด๋ฆ„์„ ์ง์ ‘ ๊ธฐ์ˆ ํ•ด์•ผ ํ•œ๋‹ค. ๋”ฐ๋ผ์„œ new๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ํด๋ผ์ด์–ธํŠธ๋Š” ์ถ”์ƒํ™”๊ฐ€ ์•„๋‹Œ ๊ตฌ์ฒด ํด๋ž˜์Šค์— ์˜์กดํ•  ์ˆ˜๋ฐ–์— ์—†๊ธฐ ๋•Œ๋ฌธ์— ๊ฒฐํ•ฉ๋„๊ฐ€ ๋†’์•„์ง„๋‹ค.
    • new ์—ฐ์‚ฐ์ž๋Š” ์ƒ์„ฑํ•˜๋ ค๋Š” ๊ตฌ์ฒด ํด๋ž˜์Šค๋ฟ๋งŒ ์•„๋‹ˆ๋ผ ์–ด๋–ค ์ธ์ž๋ฅผ ์ด์šฉํ•ด ํด๋ž˜์Šค์˜ ์ƒ์„ฑ์ž๋ฅผ ํ˜ธ์ถœํ•ด์•ผ ํ•˜๋Š”์ง€๋„ ์•Œ์•„์•ผ ํ•œ๋‹ค. ๋”ฐ๋ผ์„œ new๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ํด๋ผ์ด์–ธํŠธ๊ฐ€ ์•Œ์•„์•ผ ํ•˜๋Š” ์ง€์‹์˜ ์–‘์ด ๋Š˜์–ด๋‚˜๊ธฐ ๋•Œ๋ฌธ์— ๊ฒฐํ•ฉ๋„๊ฐ€ ๋†’์•„์ง„๋‹ค.
  • ๊ตฌ์ฒด ํด๋ž˜์Šค์— ์ง์ ‘ ์˜์กดํ•˜๋ฉด ๊ฒฐํ•ฉ๋„๊ฐ€ ๋†’์•„์ง„๋‹ค. ์—ฌ๊ธฐ์— new๋Š” ๋ฌธ์ œ๋ฅผ ๋” ํฌ๊ฒŒ ๋งŒ๋“œ๋Š”๋ฐ ํด๋ผ์ด์–ธํŠธ๋Š” ๊ตฌ์ฒด ํด๋ž˜์Šค๋ฅผ ์ƒ์„ฑํ•˜๋Š” ๋ฐ ์–ด๋–ค ์ •๋ณด๊ฐ€ ํ•„์š”ํ•œ์ง€์— ๋Œ€ํ•ด์„œ๋„ ์•Œ์•„์•ผ ํ•˜๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค.
  • new๋Š” ๊ฒฐํ•ฉ๋„๋ฅผ ๋†’์ด๊ธฐ ๋•Œ๋ฌธ์— ํ•ด๋กญ๋‹ค. ํ˜‘๋ ฅํ•  ํด๋ž˜์Šค์˜ ์ธ์Šคํ„ด์Šค๋ฅผ ์ƒ์„ฑํ•˜๊ธฐ ์œ„ํ•ด ์–ด๋–ค ์ธ์ž๋“ค์ด ํ•„์š”ํ•˜๊ณ  ๊ทธ ์ธ์ž๋“ค์„ ์–ด๋–ค ์ˆœ์„œ๋กœ ์‚ฌ์šฉํ•ด์•ผ ํ•˜๋Š”์ง€์— ๋Œ€ํ•œ ์ •๋ณด๋„ ๋…ธ์ถœ์‹œํ‚ฌ๋ฟ๋งŒ ์•„๋‹ˆ๋ผ ์ธ์ž๋กœ ์‚ฌ์šฉ๋˜๋Š” ๊ตฌ์ฒด ํด๋ž˜์Šค์— ๋Œ€ํ•œ ์˜์กด์„ฑ์„ ์ถ”๊ฐ€ํ•œ๋‹ค.
  • ํ•ด๊ฒฐ ๋ฐฉ๋ฒ•์€ ์ธ์Šคํ„ด์Šค๋ฅผ ์ƒ์„ฑํ•˜๋Š” ๋กœ์ง๊ณผ ์ƒ์„ฑ๋œ ์ธ์Šคํ„ด์Šค๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๋กœ์ง์„ ๋ถ„๋ฆฌํ•˜๋Š” ๊ฒƒ์ด๋‹ค.
  • ์™ธ๋ถ€์—์„œ ์ธ์Šคํ„ด์Šค๋ฅผ ์ „๋‹ฌ๋ฐ›๋Š” ๋ฐฉ๋ฒ•์€ ์˜์กด์„ฑ ํ•ด๊ฒฐ ๋ฐฉ๋ฒ•๊ณผ ๋™์ผํ•˜๊ฒŒ ์ƒ์„ฑ์ž์˜ ์ธ์ž๋กœ ์ „๋‹ฌํ•˜๊ฑฐ๋‚˜, setter ๋ฉ”์„œ๋“œ๋ฅผ ์‚ฌ์šฉํ•˜๊ฑฐ๋‚˜, ์‹คํ–‰ ์‹œ์— ๋ฉ”์„œ๋“œ์˜ ์ธ์ž๋กœ ์ „๋‹ฌํ•˜๋ฉด ๋œ๋‹ค.
  • ์‚ฌ์šฉ๊ณผ ์ƒ์„ฑ์˜ ์ฑ…์ž„์„ ๋ถ„๋ฆฌํ•˜๊ณ , ์˜์กด์„ฑ์„ ์ƒ์„ฑ์ž์— ๋ช…์‹œ์ ์œผ๋กœ ๋“œ๋Ÿฌ๋‚ด๊ณ , ๊ตฌ์ฒด ํด๋ž˜์Šค๊ฐ€ ์•„๋‹Œ ์ถ”์ƒ ํด๋ž˜์Šค์— ์˜์กดํ•˜๊ฒŒ ํ•จ์œผ๋กœ์จ ์„ค๊ณ„๋ฅผ ์œ ์—ฐํ•˜๊ฒŒ ๋งŒ๋“ค ์ˆ˜ ์žˆ๋‹ค. ๊ทธ๋ฆฌ๊ณ  ๊ทธ ์ถœ๋ฐœ์€ ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•˜๋Š” ์ฑ…์ž„์„ ๊ฐ์ฒด ๋‚ด๋ถ€๊ฐ€ ์•„๋‹ˆ๋ผ ํด๋ผ์ด์–ธํŠธ๋กœ ์˜ฎ๊ธฐ๋Š” ๊ฒƒ์— ์‹œ์ž‘ํ—€๋‹ค๋Š” ์ ์„ ๊ธฐ์–ตํ•˜๋ผ.

๐ŸŽˆ ๊ฐ€๋”์€ ์ƒ์„ฑํ•ด๋„ ๋ฌด๋ฐฉํ•˜๋‹คโ€‹

  • ํด๋ž˜์Šค ์•ˆ์—์„œ ๊ฐ์ฑ„์˜ ์ธ์Šคํ„ด์Šค๋ฅผ ์ง์ ‘ ์ƒ์„ฑํ•˜๋Š” ๋ฐฉ์‹์ด ์œ ์šฉํ•œ ๊ฒฝ์šฐ๋„ ์žˆ๋‹ค. ์ฃผ๋กœ ํ˜‘๋ ฅํ•˜๋Š” ๊ฐœ๋ณธ ๊ฐ์ฒด๋ฅผ ์„ค์ •ํ•˜๊ณ  ์‹ถ์€ ๊ฒฝ์šฐ๊ฐ€ ์—ฌ๊ธฐ์— ์†ํ•œ๋‹ค.
  • ์˜ˆ๋ฅผ ๋“ค์–ด, Movie๊ฐ€ ๋Œ€๋ถ€๋ถ„์˜ ๊ฒฝ์šฐ์—๋Š” AmountDiscountPolicy์˜ ์ธ์Šคํ„ด์Šค์™€ ํ˜‘๋ ฅํ•˜๊ณ  ๊ฐ€๋”์”ฉ๋งŒ PercentDiscountPolicy์˜ ์ธ์Šคํ„ด์Šค์™€ ํ˜‘๋ ฅํ•œ๋‹ค๊ณ  ๊ฐ€์ •ํ•œ๋‹ค. ๋งŒ์•ฝ ์ด ์ƒํ™ฉ์—์„œ ๋ชจ๋“  ๊ฒฝ์šฐ์— ์ธ์Šคํ„ด์Šค๋ฅผ ์ƒ์„ฑํ•˜๋Š” ์ฑ…์ž„์„ ํด๋ผ์ด์–ธํŠธ๋กœ ์˜ฎ๊ธด๋‹ค๋ฉด ํด๋ผ์ด์–ธํŠธ๋“ค ์‚ฌ์ด์— ์ค‘๋ณต ์ฝ”๋“œ๊ฐ€ ๋Š˜์–ด๋‚˜๊ณ  Movie์˜ ์‚ฌ์šฉ์„ฑ๋„ ๋‚˜๋น ์งˆ ๊ฒƒ์ด๋‹ค.
  • ์ด ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•˜๋Š” ๋ฐฉ๋ฒ•์€ ๊ธฐ๋ณธ ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•˜๋Š” ์ƒ์„ฑ์ž๋ฅผ ์ถ”๊ฐ€ํ•˜๊ณ  ์ด ์ƒ์„ฑ์ž์—์„œ DiscountPolicy์˜ ์ธ์Šคํ„ด์Šค๋ฅผ ์ธ์ž๋กœ ๋ฐ›๋Š” ์ƒ์„ฑ์ž๋ฅผ ์ฒด์ด๋‹ํ•˜๋Š” ๊ฒƒ์ด๋‹ค.
public class Movie {
// ...
private DiscountPolicy discountPolicy;

public Movie(String title, Duration runningTime) {
// ๋‘ ๋ฒˆ์งธ ์ƒ์„ฑ์ž ํ˜ธ์ถœ
// ์ƒ์„ฑ์ž๊ฐ€ ์ฒด์ธ์ฒ˜๋Ÿผ ์—ฐ๊ฒฐ
this(title, runningTime, fee, new AmountDiscountPolicy(...));
}

public Movie(String title, Duration runningTime, Money fee, DiscountPolicy discountPolicy) {
// ...
this.discountPolicy = discountPolicy;
}
}
  • ์ด ๋ฐฉ๋ฒ•์œผ๋กœ ๋ฉ”์„œ๋“œ๋ฅผ ์˜ค๋ฒ„๋กœ๋”ฉํ•˜๋Š” ๊ฒฝ์šฐ์—๋„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.
public class Movie {
public Money calculateMovieFee(Screening screening) {
return calculateMovieFee(screening, new AmountDiscountPolicy(...));
}

public Money calculateMovieFee(Screening screening, DiscountPolicy discountPolicy) {
return fee.minus(discountPolicy.calculateDiscountAmount(screening));
}
}
  • ๊ตฌ์ฒด ํด๋ž˜์Šค์— ์˜์กดํ•˜๊ฒŒ ๋˜๋”๋ผ๋„ ํด๋ž˜์Šค์˜ ์‚ฌ์šฉ์„ฑ์ด ๋” ์ค‘์š”ํ•˜๋‹ค๋ฉด ๊ฒฐํ•ฉ๋„๋ฅผ ๋†’์ด๋Š” ๋ฐฉํ–ฅ์œผ๋กœ ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•  ์ˆ˜ ์žˆ๋‹ค. ๊ทธ๋Ÿผ์—๋„ ๊ฐ€๊ธ‰์  ๊ตฌ์ฒด ํด๋ž˜์Šค์— ๋Œ€ํ•œ ์˜์กด์„ฑ์„ ์ œ๊ฑฐํ•  ์ˆ˜ ์žˆ๋Š” ๋ฐฉ๋ฒ•์„ ์ฐพ์•„๋ณด๋Š” ๊ฒƒ์ด ์ข‹๋‹ค.

๐ŸŽˆ ํ‘œ์ค€ ํด๋ž˜์Šค์— ๋Œ€ํ•œ ์˜์กด์€ ํ•ด๋กญ์ง€ ์•Š๋‹คโ€‹

  • ์ž๋ฐ”๋ผ๋ฉด JDK์— ํฌํ•จ๋œ ํ‘œ์ค€ ํด๋ž˜์Šค ์ฆ‰, ๋ณ€๊ฒฝ๋  ํ™•๋ฅ ์ด ๊ฑฐ์˜ ์—†๋Š” ํด๋ž˜์Šค๋Š” ์˜์กด์„ฑ์— ๋ฌธ์ œ๊ฐ€ ๋˜์ง€ ์•Š๋Š”๋‹ค.
  • ์ด๋Ÿฐ ํด๋ž˜์Šค๋“ค์— ๋Œ€ํ•ด์„œ๋Š” ๊ตฌ์ฒด ํด๋ž˜์Šค์— ์˜์กดํ•˜๊ฑฐ๋‚˜ ์ง์ ‘ ์ธ์Šคํ„ด์Šค๋ฅผ ์ƒ์„ฑํ•˜๋”๋ผ๋„ ๋ฌธ์ œ๊ฐ€ ์—†๋‹ค.
public abstract class DiscountPolicy {
private List<DiscountCondition> conditions = new ArrayList<>();

public void switchConditions(List<DiscountCondition> conditions) {
this.conditions = conditions;
}
}

๐ŸŽˆ ์ปจํ…์ŠคํŠธ ํ™•์žฅํ•˜๊ธฐโ€‹

  • ๋‹ค์Œ ์˜ˆ์ œ์—์„œ๋Š” ๋‹ค๋ฅธ ์ปจํ…์ŠคํŠธ์—์„œ Movie๋ฅผ ํ™•์žฅํ•ด์„œ ์žฌ์‚ฌ์šฉํ•˜๋Š” ๋‘ ๊ฐ€์ง€ ์˜ˆ๋ฅผ ๋ณธ๋‹ค. ํ•˜๋‚˜๋Š” ํ• ์ธ ํ˜œํƒ์„ ์ œ๊ณตํ•˜์ง€ ์•Š๋Š” ์˜ํ™”์ด๊ณ  ๋‹ค๋ฅธ ํ•˜๋‚˜๋Š” ๋‹ค์ˆ˜์˜ ํ• ์ธ ์ •์ฑ…์„ ์ค‘๋ณตํ•ด์„œ ์ ์šฉํ•˜๋Š” ์˜ํ™”์ด๋‹ค.
  • ์ฒซ ๋ฒˆ์งธ๋Š” ํ• ์ธ ํ˜œํƒ์„ ์ œ๊ณตํ•˜์ง€ ์•Š๋Š” ์˜ํ™”์˜ ์˜ˆ๋งค ์š”๊ธˆ์„ ๊ณ„์‚ฐํ•˜๋Š” ๊ฒฝ์šฐ๋‹ค.
  • ํ• ์ธ ์ •์ฑ…์ด ์กด์žฌํ•˜์ง€ ์•Š๋Š”๋‹ค๋Š” ์‚ฌ์‹ค์„ ํ• ์ธ ์ •์ฑ…์˜ ํ•œ ์ข…๋ฅ˜๋กœ ๊ฐ„์ฃผํ•˜์—ฌ NoneDiscountPolicy ํด๋ž˜์Šค๋ฅผ ์ถ”๊ฐ€ํ•˜๊ณ  DiscountPolicy์˜ ์ž์‹ ํด๋ž˜์Šค๋กœ ๋งŒ๋“ ๋‹ค.
public class NoneDiscountPolicy extends DiscountPolicy {
@Override
protected Money getDiscountAmount(Screening screening) {
return Money.ZERO;
}
}
  • ์ด์ œ ๋‹ค์Œ๊ณผ ๊ฐ™์ด NoneDiscountPolicy์˜ ์ธ์Šคํ„ด์Šค๋ฅผ Movie์˜ ์ƒ์„ฑ์ž์— ์ „๋‹ฌํ•œ๋‹ค.
Movie avatar = new Movie("์•„๋ฐ”ํƒ€",
Duration.ofMinutes(120),
Money.wons(10000),
new NoneDiscountPolicy()
);
  • ๋‘ ๋ฒˆ์งธ ์˜ˆ๋Š” ์ค‘๋ณต ์ ์šฉ์ด ๊ฐ€๋Šฅํ•œ ํ• ์ธ ์ •์ฑ…์„ ๊ตฌํ˜„ํ•˜๋Š” ๊ฒƒ์ด๋‹ค. (๊ธˆ์•ก ํ• ์ธ ์ •์ฑ…๊ณผ ๋น„์œจ ํ• ์ธ ์ •์ฑ…์˜ ํ˜ผํ•ฉ ์ ์šฉ)
  • ์ด ๋ฌธ์ œ๋„ NoneDiscountPolicy์™€ ๊ฐ™์€ ๋ฐฉ๋ฒ•์œผ๋กœ ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ๋Š”๋ฐ ์ค‘๋ณต ํ• ์ธ ์ •์ฑ…์„ ํ• ์ธ ์ •์ฑ…์˜ ํ•œ ๊ฐ€์ง€๋กœ ๊ฐ„์ฃผํ•œ๋‹ค.
public class OverlappedDiscountPolicy extends DiscountPolicy {
private List<DiscountPolicy> discountPolicies = new ArrayList<>();

public OverlappedDiscountPolicy(DiscountPolicy ...discountPolicies) {
this.discountPolicies = Arrays.asList(discountPolicies);
}

@Override
protected Money getDiscountAmount(Screening screening) {
Money result = Money.ZERO;

for(DiscountPolicy each : discountPolicies) {
result = result.plus(each.calculateDiscountAmount(screening));
}

return result;
}
}
  • ์ด์ œ OverlappedDiscountPolicy์˜ ์ธ์Šคํ„ด์Šค๋ฅผ ์ƒ์„ฑํ•ด์„œ Movie์— ์ „๋‹ฌํ•˜๋Š” ๊ฒƒ๋งŒ์œผ๋กœ๋„ ์ค‘๋ณต ํ• ์ธ์„ ์‰ฝ๊ฒŒ ์ ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.
Movie avatar = new Movie("์•„๋ฐ”ํƒ€",
Duration.ofMinutes(120),
Money.wons(10000),
new OverlappedDiscountPolicy(
new AmountDiscountPolicy(...),
new PercentDiscountPolicy(...)
)
);
  • ์„ค๊ณ„๋ฅผ ์œ ์—ฐํ•˜๊ฒŒ ๋ฏผ๋“ค ์ˆ˜ ์žˆ์—ˆ๋˜ ์ด์œ ๋Š” Movie๊ฐ€ DiscountPolicy๋ผ๋Š” ์ถ”์ƒํ™”์— ์˜์กดํ•˜๊ณ , ์ƒ์„ฑ์ž๋ฅผ ํ†ตํ•ด DiscountPolicy์— ๋Œ€ํ•œ ์˜์กด์„ฑ์„ ๋ช…์‹œ์ ์œผ๋กœ ๋“œ๋Ÿฌ๋ƒˆ์œผ๋ฉฐ, new์™€ ๊ฐ™์ด ๊ตฌ์ฒด ํด๋ž˜์Šค๋ฅผ ์ง์ ‘์ ์œผ๋กœ ๋‹ค๋ค„์•ผ ํ•˜๋Š” ์ฑ…์ž„์„ Movie์™ธ๋ถ€๋กœ ์˜ฎ๊ฒผ๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค.

๐ŸŽˆ ์กฐํ•ฉ ๊ฐ€๋Šฅํ•œ ํ–‰๋™โ€‹

  • ์–ด๋–ค ๊ฐ์ฒด์™€ ํ˜‘๋ ฅํ•˜๋Š๋ƒ์— ๋”ฐ๋ผ ๊ฐ์ฒด์˜ ํ–‰๋™์ด ๋‹ฌ๋ผ์ง€๋Š” ๊ฒƒ์€ ์œ ์—ฐํ•˜๊ณ  ์žฌ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•œ ์„ค๊ณ„๊ฐ€ ๊ฐ€์ง„ ํŠน์ง•์ด๋‹ค.
  • ์œ ์—ฐํ•˜๊ณ  ์žฌ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•œ ์„ค๊ณ„๋Š” ์‘์ง‘๋„ ๋†’์€ ์ฑ…์ž„๋“ค์„ ๊ฐ€์ง„ ์ž‘์€ ๊ฐ์ฒด๋“ค์„ ๋‹ค์–‘ํ•œ ๋ฐฉ์‹์œผ๋กœ ์—ฐ๊ฒฐํ•จ์œผ๋กœ์จ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์˜ ๊ธฐ๋Šฅ์„ ์‰ฝ๊ฒŒ ํ™•์žฅํ•  ์ˆ˜ ์žˆ๋‹ค.
  • ์œ ์—ฐํ•˜๊ณ  ์žฌ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•œ ์„ค๊ณ„๋Š” ๊ฐ์ฒด๊ฐ€ ์–ด๋–ป๊ฒŒ(how) ํ•˜๋Š”์ง€๋ฅผ ๋‚˜์—ดํ•˜๋Š” ๊ฒƒ์ด ์•„๋‹ˆ๋ผ ๊ฐ์ฒด๋“ค์˜ ์กฐํ•ฉ์„ ํ†ตํ•ด ๋ฌด์—‡(what)์„ ํ•˜๋Š”์ง€๋ฅผ ํ‘œํ˜„ํ•˜๋Š” ํด๋ž˜์Šค๋“ค๋กœ ๊ตฌ์„ฑ๋œ๋‹ค. ๋”ฐ๋ผ์„œ ํด๋ž˜์Šค์˜ ์ธ์Šคํ„ด์Šค๋ฅผ ์ƒ์„ฑํ•˜๋Š” ์ฝ”๋“œ๋ฅผ ๋ณด๋Š” ๊ฒƒ๋งŒ์œผ๋กœ๋„ ๊ฐ์ฒด๊ฐ€ ์–ด๋–ค ์ผ์„ ํ•˜๋Š”์ง€๋ฅผ ์‰ฝ๊ฒŒ ํŒŒ์•…ํ•  ์ˆ˜ ์žˆ๋‹ค. ๋‹ค์‹œ ๋งํ•ด ์„ ์–ธ์ ์œผ๋กœ ๊ฐ์ฒด์˜ ํ–‰๋™์„ ์ •์˜ํ•  ์ˆ˜ ์žˆ๋Š” ๊ฒƒ์ด๋‹ค.
  • ์œ ์—ฐํ•˜๊ณ  ์žฌ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•œ ์„ค๊ณ„๋Š” ์ž‘์€ ๊ฐ์ฒด๋“ค์˜ ํ–‰๋™์„ ์กฐํ•ฉํ•จ์œผ๋กœ์จ ์ƒˆ๋กœ์šด ํ–‰๋™์„ ์ด๋Œ์–ด๋‚ผ ์ˆ˜ ์žˆ๋Š” ์„ค๊ณ„๋‹ค. ํ›Œ๋ฅญํ•œ ๊ฐ์ฒด์ง€ํ–ฅ ์„ค๊ณ„๋ž€ ๊ฐ์ฒด๊ฐ€ ์–ด๋–ป๊ฒŒ ํ•˜๋Š”์ง€๋ฅผ ํ‘œํ˜„ํ•˜๋Š” ๊ฒƒ์ด ์•„๋‹ˆ๋ผ ๊ฐ์ฒด๋“ค์˜ ์กฐํ•ฉ์„ ์„ ์–ธ์ ์œผ๋กœ ํ‘œํ˜„ํ•จ์œผ๋กœ์จ ๊ฐ์ฒด๋“ค์ด ๋ฌด์—‡์„ ํ•˜๋Š”์ง€๋ฅผ ํ‘œํ˜„ํ•˜๋Š” ์„ค๊ณ„๋‹ค.
  • ์ด๋Ÿฌํ•œ ์„ค๊ณ„๋ฅผ ์ฐฝ์กฐํ•˜๋Š” ๋ฐ ์žˆ์–ด์„œ์˜ ํ•ต์‹ฌ์€ ์˜์กด์„ฑ์„ ๊ด€๋ฆฌํ•˜๋Š” ๊ฒƒ์ด๋‹ค.