[์˜ค๋ธŒ์ ํŠธ 2์žฅ] - ๊ฐ์ฒด์ง€ํ–ฅ ํ”„๋กœ๊ทธ๋ž˜๋ฐ

2024. 6. 29. 20:23ใ†๋„์„œ

[์˜ค๋ธŒ์ ํŠธ 2์žฅ] - ๊ฐ์ฒด์ง€ํ–ฅ ํ”„๋กœ๊ทธ๋ž˜๋ฐ

 

- ๋ชจ๋“  ์ด๋ฏธ์ง€์˜ ์ถœ์ฒ˜๋Š” ์˜ค๋ธŒ์ ํŠธ(์กฐ์šฉํ˜ธ ์ €) ์ฑ… ์ž…๋‹ˆ๋‹ค.

 

 

 ๊ฐ์ฒด์ง€ํ–ฅ ํ”„๋กœ๊ทธ๋ž˜๋ฐ์„ ํ–ฅํ•ด

 

๊ฐ์ฒด์ง€ํ–ฅ ํ”„๋กœ๊ทธ๋ž˜๋ฐ์€ ํด๋ž˜์Šค๋ฅผ ๋จผ์ € ๊ณ ๋ฏผํ•˜๋Š” ๊ฒƒ์ด ์•„๋‹ˆ๋ผ ๊ฐ์ฒด์— ์ง‘์ค‘ํ•ด์•ผ ํ•œ๋‹ค. ๋‹ค์Œ ๋‘ ๊ฐ€์ง€๋ฅผ ์ง‘์ค‘ํ•ด๋ณด์ž.

 

1) ์–ด๋–ค ํด๋ž˜์Šค๊ฐ€ ํ•„์š”ํ•œ์ง€๋ฅผ ๊ณ ๋ฏผํ•˜๊ธฐ ์ „์— ์–ด๋–ค ๊ฐ์ฒด๊ฐ€ ํ•„์š”ํ•œ์ง€ ๊ณ ๋ฏผํ•˜์ž. ์–ด๋–ค ๊ฐ์ฒด๋“ค์ด ์–ด๋–ค ํ–‰๋™์„ ํ•˜๊ณ  ์–ด๋–ค ์ƒํƒœ๋ฅผ ๊ฐ€์ง€๋Š”์ง€๋ฅผ ๋จผ์ € ๊ฒฐ์ •ํ•œ๋‹ค.

2) ๊ฐ์ฒด๋ฅผ ๋…๋ฆฝ์ ์ธ ์กด์žฌ๊ฐ€ ์•„๋‹ˆ๋ผ ํ˜‘๋ ฅํ•˜๋Š” ๊ณต๋™์ฒด์˜ ์ผ์›์œผ๋กœ ๋ฐ”๋ผ๋ด์•ผ ํ•œ๋‹ค. 

 

 

 

 

 ๋„๋ฉ”์ธ์˜ ๊ตฌ์กฐ๋ฅผ ๋”ฐ๋ฅด๋Š” ํ”„๋กœ๊ทธ๋žจ ๊ตฌ์กฐ

 

๋„๋ฉ”์ธ์€ ์‚ฌ์šฉ์ž์˜ ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•˜๊ธฐ ์œ„ํ•ด ํ”„๋กœ๊ทธ๋žจ์„ ์‚ฌ์šฉํ•˜๋Š” ๋ถ„์•ผ๋ฅผ ์ผ์ปซ๋Š”๋‹ค. ์˜ํ™”์˜ˆ๋งค ํ”„๋กœ๊ทธ๋žจ์—์„œ '์˜ํ™”์˜ˆ๋ฉ”'๋Š” ๋„๋ฉ”์ธ์— ์†ํ•œ๋‹ค. 

 

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

 

 

 

์˜ํ™”๋Š” ์—ฌ๋Ÿฌ ๋ฒˆ ์ƒ์˜๋  ์ˆ˜ ์žˆ๊ณ , ์ƒ์˜์€ ์—ฌ๋Ÿฌ ๋ฒˆ ์˜ˆ๋งค ๋  ์ˆ˜ ์žˆ๋‹ค๋Š” ๊ฒƒ์„ ์•Œ ์ˆ˜ ์žˆ๋‹ค. ๋˜ํ•œ ์˜ํ™”๋Š” ํ• ์ธ์ •์ฑ…์ด ์žˆ์„ ์ˆ˜๋„ ์žˆ๊ณ , ํ• ์ธ ์ •์ฑ…์ด ์กด์žฌํ•œ๋‹ค๋ฉด ํ• ์ธ ์กฐ๊ฑด์ด ๋ฐ˜๋“œ์‹œ ํ•˜๋‚˜ ์ด์ƒ์ด ์กด์žฌํ•ด์•ผ ํ•จ์„ ์•Œ ์ˆ˜ ์žˆ๋‹ค. 

 

๋„๋ฉ”์ธ์˜ ๊ตฌ์กฐ๋ฅผ ํด๋ž˜์Šค์™€ ๋งค์นญ ์‹œํ‚ค๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์•„์ง„๋‹ค. 

 

 

 

 

 

 ํด๋ž˜์Šค ๊ตฌํ˜„ํ•˜๊ธฐ

 

 

public class Screening {
    private Movie movie;
    private int sequence;
    private LocalDateTime whenScreened;
    
    public Screening(Movie movie, int sequence, LocalDateTime whenScreened) {
        this.movie = movie;
        this.sequence = sequence;
        this.whenScreened = whenScreened;
    }
    
    public LocalDateTime geetStartTime() {
        return whenScreened;
    }
    
    public boolean isSequence(int sequence) {
        return this.sequence == sequence;
    }
    
    public Money getMovieFee() {
        return movie.getFee();
    }
}

 

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

 

๊ฐ์ฒด๋Š” 1) '์ƒํƒœ'์™€ 'ํ–‰๋™'์„ ํ•จ๊ป˜ ๊ฐ€์ง€๋Š” ๋ณตํ•ฉ์ ์ธ ์กด์žฌ์ด๋ฉด์„œ 2) ์Šค์Šค๋กœ ํŒ๋‹จํ•˜๊ณ  ํ–‰๋™ํ•˜๋Š” '์ž์œจ์ ์ธ ์กด์žฌ'์ด๋‹ค. 

 

๊ฐ์ฒด์ง€ํ–ฅ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์–ธ์–ด๋“ค์€ ๋Œ€๋ถ€๋ถ„ ์ ‘๊ทผ์ œ์–ด์ž๋ฅผ ์ง€์›ํ•œ๋‹ค.

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

 

์ง์ ‘ ๊ฐœ์ž…ํ•˜์ง€ ๋ง๊ณ  ์›ํ•˜๋Š” ๊ฑธ ์š”์ฒญํ•˜๊ณ  ์Šค์Šค๋กœ ์ตœ์„ ์˜ ๊ฒฐ์ •์„ ๋‚ด๋ฆฌ๋„๋ก ๊ธฐ๋‹ค๋ฆฌ์ž. 

 

์ธํ„ฐํŽ˜์ด์Šค์™€ ๊ตฌํ˜„์„ ๋ถ„๋ฆฌํ•ด์•ผ ํ•˜๋Š” ๊ฐ€์žฅ ํฐ ์ด์œ ๋Š” ๋ณ€๊ฒฝ์— ์šฉ์ดํ•˜๊ธฐ ์œ„ํ•ด์„œ์ž„์„ ๊ธฐ์–ตํ•˜์ž.

 

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

 

 

 

 

 ํ˜‘๋ ฅํ•˜๋Š” ๊ฐ์ฒด๋“ค์˜ ๊ณต๋™์ฒด

 

public class Money {
    public static final Money ZERO = Money.wons(0);
    
    private final BigDecimal amount;
    
    public static Money wons(BigDecimal amount) {
        return new Money(BigDecimal.valueOf(amount));
    }
}

 

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

๋”ฐ๋ผ์„œ ์˜๋ฏธ๋ฅผ ์ข€ ๋” ๋ช…์‹œ์ ์ด๊ณ  ๋ถ„๋ช…ํ•˜๊ฒŒ ํ‘œํ˜„ํ•  ์ˆ˜ ์žˆ๋‹ค๋ฉด ๊ฐ์ฒด๋ฅผ ์ด์šฉํ•ด์„œ ํ•ด๋‹น ๊ฐœ๋…์„ ๊ตฌํ˜„ํ•˜๋ผ.  ๊ทธ ๊ฐœ๋…์ด ๋น„๋ก ์ธ์Šคํ„ด์Šค ๋ณ€์ˆ˜๋ฅผ ํฌํ•จํ•˜๋”๋ผ๋„ ๋ง์ด๋‹ค. 

 

๊ฐ์ฒด๊ฐ€ ๋‹ค๋ฅธ ๊ฐ์ฒด์™€ ์ƒํ˜ธ์ž‘์šฉํ•  ์ˆ˜ ์žˆ๋Š” ๋ฐฉ๋ฒ•์€ ๋ฉ”์‹œ์ง€๋ฅผ ์ „์†กํ•˜๋Š” ๊ฒƒ ๋ฟ์ด๋‹ค. ์ด์™€ ์œ ์‚ฌํ•œ ๊ฐœ๋…์œผ๋กœ ๋ฉ”์„œ๋“œ๊ฐ€ ์žˆ๋Š”๋ฐ, ๋ฉ”์„œ๋“œ๋Š” ์ˆ˜์‹ ๋œ ๋ฉ”์‹œ์ง€๋ฅผ ์ฒ˜๋ฆฌํ•˜๊ธฐ ์œ„ํ•œ ์ž์‹ ๋งŒ์˜ ๋ฐฉ๋ฒ•์„ ์˜๋ฏธํ•œ๋‹ค. 

 

 

 

 ํ• ์ธ ์š”๊ธˆ ๊ตฌํ•˜๊ธฐ

 

์˜ํ™”์˜ˆ๋งค ๊ธˆ์•ก์„ ๊ตฌํ•  ํ• ์ธ ์ •์ฑ… ํด๋ž˜์Šค๋ฅผ ๋งŒ๋“ค์–ด๋ณด์ž. 

 

๋จผ์ € ํ• ์ธ ์ •์ฑ…์€ ๊ธˆ์•ก ํ• ์ธ ์ •์ฑ…๊ณผ ๋น„์œจ ํ• ์ธ ์ •์ฑ…์œผ๋กœ ๊ตฌ๋ถ„๋œ๋‹ค. ๋‘ ๊ฐ€์ง€ ํ• ์ธ ์ •์ฑ…์„ ๊ฐ๊ฐ AmountDiscountPolicy์™€ PercentDiscountPolicy๋กœ ๊ตฌ๋ถ„ํ•œ๋‹ค. ๋‘ ํด๋ž˜์Šค๋Š” ์œ ์‚ฌํ•˜๊ธฐ ๋•Œ๋ฌธ์— ์ค‘๋ณต ์ฝ”๋“œ๋ฅผ ์ œ๊ฑฐํ•˜๊ธฐ ์œ„ํ•ด ๊ณตํ†ต ์ฝ”๋“œ๋ฅผ ๋ณด๊ด€ํ•  ์žฅ์†Œ๊ฐ€ ํ•„์š”ํ•˜๋‹ค. ๋”ฐ๋ผ์„œ ์ถ”์ƒ ํด๋ž˜์Šค๋ฅผ ์‚ฌ์šฉํ•ด๋ณด์ž.

 

public abstract class DiscountPolicy {
    private List<DiscountCondition> conditions = new ArrayList<>();
    
    public DiscountPolicy(DiscountCondition ... conditions) {
        this.conditions = conditions;
    }
    
    public Money calculateDiscountAmount(Screening screening) {
        for(DiscountCondition each : conditions) {
            if (each.isSatisFiedBy(screening)) {
                return getDiscountAmount(screening)
            }
        }
        
        return Money.ZERO;
    }
    
    abstract Money getDiscountAmount(Screening screening);
}

 

ํ• ์ธ ์กฐ๊ฑด์„ ๋งŒ์กฑํ•˜๋Š” DiscountCondition์ด ํ•˜๋‚˜๋ผ๋„ ์กด์žฌํ•˜๋Š” ๊ฒฝ์šฐ์—๋Š” '์ถ”์ƒ ๋ฉ”์„œ๋“œ'์ธ getDiscountAmount๋ฅผ ํ˜ธ์ถœํ•ด์„œ ํ• ์ธ ์š”๊ธˆ์„ ๊ณ„์‚ฐํ•œ๋‹ค.

 

DiscountPolicy๋Š” ํ• ์ธ ์—ฌ๋ถ€์™€ ๊ณ„์‚ฐํ•˜๋Š” ํ๋ฆ„์„ ์ •์˜ํ•˜์ง€๋งŒ ์‹ค์ œ๋กœ ๊ณ„์‚ฐํ•˜๋Š” ๋ถ€๋ถ„์€ ์ž์‹ ํด๋ž˜์Šค์—์„œ ์˜ค๋ฒ„๋ผ์ด๋”ฉ ํ•œ ๋ฉ”์„œ๋“œ์— ์œ„์ž„ํ•œ๋‹ค. ์ด์ฒ˜๋Ÿผ ๋ถ€๋ชจํด๋ž˜์Šค์— ๊ธฐ๋ณธ์ ์ธ ์•Œ๊ณ ๋ฆฌ์ฆ˜์„ ๊ตฌํ˜„ํ•˜๊ณ  ์ค‘๊ฐ„์— ํ•„์š”ํ•œ ์ฒ˜๋ฆฌ๋ฅผ ์ž์‹ ํด๋ž˜์Šค์— ์œ„์ž„ํ•˜๋Š” ๋””์ž์ธ ํŒจํ„ด์„ 'TEMPLATE METHOD'(ํ…œํ”Œ๋ฆฟ ๋ฉ”์„œ๋“œ) ํŒจํ„ด์ด๋ผ๊ณ  ํ•œ๋‹ค.

 

 

DiscountCondition์€ ์ž๋ฐ”์˜ ์ธํ„ฐํŽ˜์ด์Šค๋กœ ๊ตฌํ˜„ํ•œ๋‹ค. 

 

public interface DiscountCondition {
    boolean isSatisfied(Screening screening);
}

 

 

๊ทธ๋ฆฌ๊ณ  ์ด ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ๊ตฌํ˜„ํ•˜๋Š” ์ˆœ์„œ์กฐ๊ฑด๊ณผ ๊ธฐ๊ฐ„ ์กฐ๊ฑด์„ ๊ตฌํ˜„ํ•œ๋‹ค.

 

public class SequenceCondition implements DiscountCondition {
    private int sequence;

    public SequenceCondition(int sequence) {
        this.sequence = sequence;
    }

    @Override
    public boolean isSatisfied(Screening screening) {
        return false;
    }
}

 

 

public class PeriodCondition implements DiscountCondition {
    private DayOfWeek dayOfWeek;
    private LocalTime startTime;
    private LocalTime endTime;
    
    public PeriodCondition(DayOfWeek dayOfWeek, LocalTime startTime, LocalTime endTime) {
        this.dayOfWeek = dayOfWeek;
        this.startTime = startTime;
        this.endTime = endTime;
    }

    @Override
    public boolean isSatisfied(Screening screening) {
        return screening.getStartTime().getDayOfWeek().equals(dayOfWeek) &&
                startTime.compareTo(screening.getStartTime().toLocalTime()) <= 0 &&
                endTime.compareTo(screening.getStartTime().toLocalTime()) >= 0;
    }
}

 

 

๋‹ค์Œ์œผ๋กœ๋Š” ํ• ์ธ ์ •์ฑ…์„ ๊ตฌํ˜„ํ•˜์ž. AmountDiscountPolicy๋Š” DiscountPolicy์˜ ์ž์‹ ํด๋ž˜์Šค๋กœ์„œ ํ• ์ธ ์กฐ๊ฑด์„ ๋งŒ์กฑํ•  ๊ฒฝ์šฐ ์ผ์ •ํ•œ ๊ธˆ์•ก์„ ํ• ์ธํ•ด์ค€๋‹ค. 

 

public class AmountDiscountPolicy implements DiscountPolicy {
    private Money discountAmount;
    
    public AmountDiscountPolicy(Money discountAmount, DiscountCondition ... conditions) {
        super(conditions);
        this.discountAmount = discountAmount;
    }
    
    @Override
    Money getDiscountAmount(Screening screening) {
        return discountAmount;
    }
}

 

PercentDiscountPolicy ์—ญ์‹œ getDiscountAmount ๋ฉ”์„œ๋“œ๋ฅผ ์˜ค๋ฒ„๋ผ์ด๋”ฉํ•˜์—ฌ ๊ตฌํ˜„ํ•œ๋‹ค.

 

public class PercentDiscountPolicy extends DiscountPolicy {
    private double percent;
    
    public PercentDiscountPolicy(double percent, DiscountCondition ... conditions) {
        super(conditions);
        this.percent = percent;
    }
    
    @Override
    protected Money getDiscountAmount(Screening screening) {
        return screening.getMovieFee().times(percent);
    }
}

 

 

์ •์ฑ…์— ๊ด€ํ•œ ๊ตฌํ˜„ํด๋ž˜์Šค๋“ค์€ ์ถ”์ƒํด๋ž˜์Šค๋ฅผ ์ƒ์†๋ฐ›๊ณ  ์žˆ๊ธฐ ๋•Œ๋ฌธ์— super๋ฅผ ํ†ตํ•ด ๋ถ€๋ชจํด๋ž˜์Šค๋ฅผ ์ดˆ๊ธฐํ™”ํ•ด์ค€๋‹ค. 

 

์œ„ ์ฝ”๋“œ๋“ค์€ ์ƒ์„ฑ์ž๋ฅผ ํ†ตํ•ด์„œ ์ดˆ๊ธฐํ™”์— ํ•„์š”ํ•œ ์ •๋ณด๋ฅผ ์˜ฌ๋ฐ”๋ฅด๊ฒŒ ์ „๋‹ฌํ•˜๋„๋ก ๊ฐ•์ œํ•˜๊ณ  ์žˆ๋‹ค. ์ด๋ฅผ ํ†ตํ•ด ํ• ์ธ ์ •์ฑ…์€ ํ•œ ์˜ํ™”๋‹น ํ•œ ๊ฐœ๋งŒ ์ ์šฉํ•˜๊ณ , ํ• ์ธ ์กฐ๊ฑด์€ ์—ฌ๋Ÿฌ ๊ฐœ๋ฅผ ์ ์šฉํ•  ์ˆ˜ ์žˆ๋„๋ก ํ•ด์ค€๋‹ค. 

 

์ด์ œ ํด๋ผ์ด์–ธํŠธ ์ธก์—์„œ ์ฝ”๋“œ๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์•„์ง„๋‹ค. 

 

Movie titanic = new Movie("ํƒ€์ดํƒ€๋‹‰",
        Duration.ofMinutes(180),
        Money.wons(11000),
        new PercentDiscountPolicy(0.1),
                new PeriodCondition(DayOfWeek.TUESDAY, LocalTime.of(14, 0), LocalTime.of(16, 59)),
                new SequenceCondition(2),
                new PeriodCondition(DayOfWeek.THURSDAY, LocalTime.of(10, 0), LocalTime.of(13, 59))
);

 

ํƒ€์ดํƒ€๋‹‰ ์˜ํ™”๊ฐ€ ๋น„์œจ ํ• ์ธ์ •์ฑ…์„ ์‚ฌ์šฉํ•˜๊ณ  ๋‘ ๊ฐœ์˜ ํ• ์ธ์กฐ๊ฑด๊ณผ ํ•œ๊ฐœ์˜ ์ˆœ์„œ์กฐ๊ฑด์ด ์žˆ๋Š” ๊ฒƒ์„ ํ•œ๋ˆˆ์— ๋ณผ ์ˆ˜ ์žˆ๋‹ค. 

 

 

 

 ์ƒ์†๊ณผ ๋‹คํ˜•์„ฑ

 

 

 

Movie๋Š” DiscountPolicy ํด๋ž˜์Šค์™€ ์—ฐ๊ฒฐ๋˜์–ด ์žˆ๋‹ค. ์ฝ”๋“œ ์ˆ˜์ค€์—์„œ๋Š” DiscountPolicy์™€ ์—ฐ๊ฒฐ๋˜์–ด ์žˆ์ง€๋งŒ ์‹ค์ œ ์ฝ”๋“œ๊ฐ€ ์‹คํ–‰๋  ๋•Œ๋Š” ๊ตฌํ˜„ํด๋ž˜์Šค์ธ AmountDiscountPolicy๋‚˜ PercentDiscountPolicy์™€ ์—ฐ๊ฒฐ๋˜์–ด ์žˆ๋‹ค. 

 

์—ฌ๊ธฐ์„œ ์ด์•ผ๊ธฐํ•˜๊ณ  ์‹ถ์€ ๊ฒƒ์€ ์ฝ”๋“œ์˜ ์˜์กด์„ฑ๊ณผ ์‹คํ–‰ ์‹œ์ ์˜ ์˜์กด์„ฑ์ด ์„œ๋กœ ๋‹ค๋ฅผ ์ˆ˜ ์žˆ๋‹ค๋Š” ๊ฒƒ์ด๋‹ค. ์œ ์—ฐํ•˜๊ณ , ์‰ฝ๊ฒŒ ์žฌ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์œผ๋ฉฐ, ํ™•์žฅ ๊ฐ€๋Šฅํ•œ ๊ฐ์ฒด์ง€ํ–ฅ ์„ค๊ณ„๊ฐ€ ๊ฐ€์ง€๋Š” ํŠน์ง•์€ ์ฝ”๋“œ์˜ ์˜์กด์„ฑ๊ณผ ์‹คํ–‰ ์‹œ์ ์˜ ์˜์กด์„ฑ์ด ๋‹ค๋ฅด๋‹ค.

 

ํ•˜์ง€๋งŒ ์ด ๋‘ ์‹œ์ ์˜ ๊ฐ„๊ทน์ด ๋ฉ€์–ด์งˆ ์ˆ˜๋ก ์ฝ”๋“œ๋ฅผ ์ดํ•ดํ•˜๊ธฐ๊ฐ€ ์–ด๋ ค์›Œ์ง„๋‹ค. ๋ฐ˜๋ฉด์— ์ดํ•ด๋Š” ์–ด๋ ต์ง€๋งŒ ์œ ์—ฐํ•˜๊ณ  ํ™•์žฅ ๊ฐ€๋Šฅํ•ด์ง„๋‹ค. ์—ญ์‹œ ์„ค๊ณ„๋Š” ํŠธ๋ ˆ์ด๋“œ์˜คํ”„์˜ ์‚ฐ๋ฌผ์ด๋‹ค. 

 

๋ฌด์กฐ๊ฑด ์œ ์—ฐํ•œ ์„ค๊ณ„๋„, ๋ฌด์กฐ๊ฑด ๊ฐ€๋…์„ฑ์ด ์ข‹์€ ์„ค๊ณ„๋„ ์ •๋‹ต์ด ์•„๋‹ˆ๋‹ค. ํ•ญ์ƒ ์ด ๋‘ ๊ฐ€์ง€ ๊ธฐ๋กœ์—์„œ ๊ณ ๋ฏผํ•ด์•ผ ํ•œ๋‹ค. (๋ฌผ๋ก  ๋‘˜ ๋‹ค ์ง€์ผœ์ง€๋ฉด ๋” ์ข‹๊ฒ ์ง€๋งŒ ๋ง์ด๋‹ค.)

 

 

 

 ์ฐจ์ด์— ์˜ํ•œ ํ”„๋กœ๊ทธ๋ž˜๋ฐ

 

๋ถ€๋ชจ์˜ ํด๋ž˜์Šค์™€ ๋‹ค๋ฅธ ๋ถ€๋ถ„๋งŒ ์ถ”๊ฐ€ํ•ด์„œ ์ƒˆ๋กœ์šด ํด๋ž˜์Šค๋ฅผ ์‰ฝ๊ณ  ๋น ๋ฅด๊ฒŒ ๋งŒ๋“œ๋Š” ๋ฐฉ๋ฒ•์„ '์ฐจ์ด์— ์˜ํ•œ ํ”„๋กœ๊ทธ๋ž˜๋ฐ'์ด๋ผ๊ณ  ๋ถ€๋ฅธ๋‹ค. 

 

์ฐจ์ด์— ์˜ํ•œ ํ”„๋กœ๊ทธ๋ž˜๋ฐ์€ ์ค‘๋ณต์ฝ”๋“œ ์—†์ด ์†์‰ฝ๊ฒŒ ๋ถ€๋ชจํด๋ž˜์Šค์˜ ๊ธฐ๋Šฅ์„ ์‚ฌ์šฉํ•˜๋ฉด์„œ ๊ธฐ๋Šฅ์„ ํ™•์žฅํ•  ์ˆ˜ ์žˆ๋‹ค. ์ด๋ฅผ ๊ฐ€๋Šฅ์ผ€ํ•˜๋Š” ๊ฒƒ ์ค‘ ํ•˜๋‚˜๊ฐ€ ์ƒ์†์ด๋‹ค. ํ•˜์ง€๋งŒ ์ƒ์†์ด ํ•ญ์ƒ ์ข‹์€ ๊ฒƒ์€ ์•„๋‹ˆ๋‹ค. ์ž์‹ ํด๋ž˜์Šค๊ฐ€ ๋ถ€๋ชจ ํด๋ž˜์Šค์— ๊ฒฐํ•ฉ๋„๊ฐ€ ๋†’์•„์ง€๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค. ์ด๋Š” ๋’ค์—์„œ ์‚ดํŽด๋ณธ๋‹ค. 

 

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

 

DiscountPolicyํƒ€์ž…์— AmountDiscountPolicy๊ฐ€ ํ• ๋‹น ๊ฐ€๋Šฅํ•œ ์ด์œ ๋Š” '์—…์บ์ŠคํŒ…'์ด ์ผ์–ด๋‚˜๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค. ์ฆ‰ ๋ถ€๋ชจํƒ€์ž…์œผ๋กœ ํƒ€์ž…์„ ์—…ํ•˜๋Š” ๊ฒƒ์ด๋‹ค. 

 

์–ธ์–ด์ฐจ์›์—์„œ ์—…์บ์ŠคํŒ…์„ ์ง€์›ํ•œ๋‹ค๋ฉด ๋‹คํ˜•์„ฑ์„ ์ง€ํ‚ฌ ์ˆ˜ ์žˆ๊ฒŒ๋œ๋‹ค. ๋‹คํ˜•์„ฑ์€ ๊ฐ์ฒด์—๊ฒŒ ๋™์ผํ•œ ๋ฉ”์‹œ์ง€๋ฅผ ๋˜์ง€์ง€๋งŒ ์‹ค์ œ๋กœ ์–ด๋–ค ๋ฉ”์„œ๋“œ๊ฐ€ ์‹คํ–‰๋  ์ง€๋Š” ์ˆ˜์‹ ํ•  ๊ฐ์ฒด์˜ ํƒ€์ž…์— ๋”ฐ๋ผ ๋ฐ”๋€Œ๋Š” ๊ฒƒ์„ ์˜๋ฏธํ•œ๋‹ค. 

 

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

 

 ์ธํ„ฐํŽ˜์ด์Šค์™€ ๋‹คํ˜•์„ฑ

 

DiscountPolicy๋ผ๋Š” ์ถ”์ƒ ํด๋ž˜์Šค๋กœ ๋‹คํ˜•์„ฑ์„ ์ถฉ์กฑํ–ˆ์ง€๋งŒ ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ํ†ตํ•ด์„œ๋„ ๋‹คํ˜•์„ฑ์„ ์ถฉ์กฑ์‹œํ‚ฌ ์ˆ˜ ์žˆ๋‹ค. 

๋‚ด๋ถ€ ๊ตฌํ˜„์„ ๊ณต์œ ํ•  ํ•„์š”์—†์ด ์ˆœ์ˆ˜ํ•˜๊ฒŒ ์ธํ„ฐํŽ˜์ด์Šค๋งŒ ๊ณต์œ ํ•˜๋„๋ก ํ•˜๋Š” ๊ฒƒ์ด๋‹ค. 

DiscountPolicy ๋‚ด๋ถ€์˜ ์ธ์Šคํ„ด์Šค์˜ ๋ณ€์ˆ˜๋กœ ์žˆ๋Š” DiscountConfition์ด ๋ฐ”๋กœ ๊ทธ ์˜ˆ๋‹ค. 

 

 

 

 ์ถ”์ƒํ™”์™€ ์œ ์—ฐ์„ฑ

 

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

 

์ถ”์ƒํ™”๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ๋‹ค์Œ ๋‘ ๊ฐ€์ง€ ์žฅ์ ์ด ์žˆ๋‹ค.

1) ์š”๊ตฌ์‚ฌํ•ญ์˜ ์ •์ฑ…์„ ๋†’์€ ์ˆ˜์ค€์—์„œ ์„œ์ˆ  ๊ฐ€๋Šฅํ•˜๋‹ค.

2) ์„ค๊ณ„๊ฐ€ ๋” ์œ ์—ฐํ•ด์ง„๋‹ค. 

 

 

์ถ”์ƒํ™”๋œ ํƒ€์ž…๋งŒ ๋ณด๊ณ  ๊ด€๊ณ„๋ฅผ ๋ดค์„๋•Œ ํ•ต์‹ฌ์ ์ธ ํ๋ฆ„์„ ํ•œ ๋ˆˆ์— ๋ณผ ์ˆ˜ ์žˆ๋‹ค.

'์˜ํ™”๋Š” ํ•˜๋‚˜์˜ ์ •์ฑ…์ด ์žˆ๊ณ  ์—ฌ๋Ÿฌ๊ฐœ์˜ ํ• ์ธ ์กฐ๊ฑด์ด ์žˆ๋‹ค'

 

์ด๋ฅผ ํ†ตํ•ด ์„ธ๋ถ€์ ์ธ ๋‚ด์šฉ์€ ๋ฌด์‹œํ•œ ์ฑ„ ํ˜‘๋ ฅ ํ๋ฆ„์„ ๊ธฐ์ˆ ํ•  ์ˆ˜ ์žˆ๋‹ค. ์žฌ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•œ ์„ค๊ณ„์˜ ๊ธฐ๋ณธ์„ ์ด๋ฃจ๋Š” '๋””์ž์ธ ํŒจํ„ด'๊ณผ 'ํ”„๋ ˆ์ž„์›Œํฌ' ๋ชจ๋‘ ์ถ”์ƒํ™”๋ฅผ ์ด์šฉํ•ด ์ƒ์œ„ ์ •์ฑ…์„ ์ •์˜ํ•˜๋Š” ๊ฐ์ฒด์ง€ํ–ฅ ๋ฉ”์ปค๋‹ˆ์ฆ˜์„ ํ™œ์šฉํ•˜๊ณ  ์žˆ๋‹ค. 

 

๋ฐ”๋กœ ์ด ์ด์ ์„ ํ™•์ธํ•˜๊ธฐ ์œ„ํ•ด ์š”๊ตฌ์‚ฌํ•ญ ์ถ”๊ฐ€๋กœ ํ™•์ธํ•ด๋ณด์ž.

 

ํ• ์ธ์ •์ฑ…์ด ์—†๋Š” ์˜ํ™”๋„ ์žˆ๋‹ค๊ณ  ๊ฐ€์ •ํ•ด๋ณด์ž. ์ฒซ๋ฒˆ์งธ ๋Œ€์‘์€ ์˜ˆ์™ธ ์ผ€์ด์Šค๋ฅผ ์ถ”๊ฐ€ํ•˜๋Š” ๊ฒƒ์ด๋‹ค.

 

public class Movie {
    public Money calculateMovieFee(Screening screening) {
        if (discountPolicy == null) {
            return fee;
        }
        
        return fee.minus(discountPolicy.calculateDiscountAmount(screening));
    }
}

 

 

๊ธฐ์กด์—๋Š” ํ• ์ธ ์ •์ฑ…์„ ์ฑ…์ž„์ง€๋Š” ์ชฝ์ด DiscountPolicy ์ธก์— ์žˆ์—ˆ์ง€๋งŒ ์œ„ ์ฝ”๋“œ๋Š” Movie์—์„œ ์ฑ…์ž„์„ ์ง€๊ณ  ์žˆ๊ธฐ์— ์ง€๊ธˆ๊นŒ์ง€์˜ ํ˜‘๋ ฅ๋ฐฉ์‹์ด ๊นจ์ง„๋‹ค. ํ•ญ์ƒ ์˜ˆ์™ธ์ผ€์ด์Šค๋ฅผ ์ตœ์†Œํ™”ํ•˜๊ณ  ์ผ๊ด€์„ฑ์„ ์œ ์ง€ํ•  ์ˆ˜ ์žˆ๋Š” ๋ฐฉ๋ฒ•์„ ์„ ํƒํ•ด์•ผ ํ•œ๋‹ค.

 

์ด๋ฅผ ์œ„ํ•ด NoneDiscountPolicy ํด๋ž˜์Šค๋ฅผ ์ถ”๊ฐ€ํ•ด๋ณด์ž.

 

public class NoneDiscountPolicy extends DiscountPolicy {
    @Override
    Money getDiscountAmount(Screening screening) {
        return Money.ZERO;
    }
}

 

์ด๋กœ์จ Movie๋ฅผ ์ˆ˜์ •ํ•˜์ง€ ์•Š๊ณ  NoneDiscountPolicy ํด๋ž˜์Šค๋ฅผ ์ถ”๊ฐ€ํ•˜๋Š” ๊ฒƒ๋งŒ์œผ๋กœ ๊ธฐ๋Šฅ์„ ํ™•์žฅํ–ˆ๋‹ค.  

์ถ”์ƒํ™”๊ฐ€ ์œ ์—ฐํ•œ ์„ค๊ณ„๋ฅผ ๊ฐ€๋Šฅ์ผ€ ํ•˜๋Š” ์ด์œ ๋Š” ์„ค๊ณ„๊ฐ€ ๊ตฌ์ฒด์ ์ธ ์ƒํ™ฉ์— ๊ฒฐํ•ฉ๋˜๋Š” ๊ฒƒ์„ ๋ฐฉ์ง€ํ•˜๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค. 

 

DiscountPolicy ์—ญ์‹œ๋„ ํŠน์ • ํ• ์ธ ์กฐ๊ฑด์— ๋ฌถ์—ฌ์žˆ์ง€ ์•Š์€๋ฐ ์ด๋Š” ์ถ”์ƒ์ ์ด๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค. ์ด๋ฅผ '์ปจํ…์ŠคํŠธ ๋…๋ฆฝ์„ฑ'์ด๋ผ๊ณ  ๋ถ€๋ฅธ๋‹ค.

 

๊ฒฐ๋ก ์€ ๊ฐ„๋‹จํ•˜๋‹ค. ์œ ์—ฐ์„ฑ์ด ํ•„์š”ํ•œ ๊ณณ์— ์ถ”์ƒํ™”๋ฅผ ์‚ฌ์šฉํ•˜์ž.

 

 

 

 

 ์ƒ์†

 

์ƒ์†์˜ ๊ฐ€์žฅ ํฐ ๋ฌธ์ œ์ ์€ ์บก์Šํ™”๋ฅผ ์œ„๋ฐ˜ํ•˜๋Š” ๊ฒƒ์ด๋‹ค. ์ƒ์†์„ ์œ„ํ•ด์„œ๋Š” ๋ถ€๋ชจ ํด๋ž˜์Šค์˜ ๋‚ด๋ถ€ ๊ตฌ์กฐ๋ฅผ ์ž˜ ์•Œ๊ณ  ์žˆ์–ด์•ผ ํ•œ๋‹ค. 

AmountDiscountMovie์™€ PercentDiscountMovie๋ฅผ ๊ตฌํ˜„ํ•˜๋Š” ๊ฐœ๋ฐœ์ž๋Š” Movie์˜ calculateMovieFee ๋ฉ”์„œ๋“œ ์•ˆ์—์„œ ์ถ”์ƒ ๋ฉ”์„œ๋“œ์ธ getDiscountAmount ๋ฉ”์„œ๋“œ๋ฅผ ํ˜ธ์ถœํ•œ๋‹ค๋Š” ์‚ฌ์‹ค์„ ์•Œ๊ณ  ์žˆ์–ด์•ผ ํ•œ๋‹ค. ์ด๋Š” ๊ฒฐ๊ณผ์ ์œผ๋กœ ๋ถ€๋ชจ ํด๋ž˜์Šค์˜ ๋ณ€๊ฒฝ์ด ์ž์‹ํด๋ž˜์Šค์˜ ๋ณ€๊ฒฝ์„ ์ดˆ๋ž˜ํ•˜๊ฒŒ ๋œ๋‹ค. 

 

๋‘ ๋ฒˆ์งธ ๋‹จ์ ์€ ์„ค๊ณ„๊ฐ€ ์œ ์—ฐํ•˜์ง€ ์•Š๋‹ค๋Š” ๊ฒƒ์ด๋‹ค. ์ƒ์†์€ ๋ถ€๋ชจ ํด๋ž˜์Šค์™€ ์ž์‹ ํด๋ž˜์Šค์˜ ๊ด€๊ณ„๊ฐ€ ์ปดํŒŒ์ผ ์‹œ์ ์— ๊ฒฐ์ •๋œ๋‹ค. ๋”ฐ๋ผ์„œ ์‹คํ–‰ ์‹œ์ ์— ๊ฐ์ฒด์˜ ์ข…๋ฅ˜๋ฅผ ๋ณ€๊ฒฝํ•˜๋Š” ๊ฒƒ์ด ๋ถˆ๊ฐ€๋Šฅํ•˜๋‹ค. 

 

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

 

ํ•ฉ์„ฑ์€ ์ƒ์†์ด ๊ฐ€์ง€๋Š” ๋‘ ๊ฐ€์ง€ ๋ฌธ์ œ์ ์„ ๋ชจ๋‘ ํ•ด๊ฒฐํ•œ๋‹ค. ์ธํ„ฐํŽ˜์ด์Šค์— ์ •์˜๋œ ๋ฉ”์‹œ์ง€๋ฅผ ํ†ตํ•ด์„œ๋งŒ ์žฌ์‚ฌ์šฉํ•˜๊ธฐ ๋•Œ๋ฌธ์— ๊ตฌํ˜„์„ ํšจ๊ณผ์ ์œผ๋กœ ์บก์Šํ™”ํ•œ๋‹ค. ๋˜ํ•œ ์ธ์Šคํ„ด์Šค๋ฅผ ๊ต์ฒดํ•˜๋Š” ๊ฒƒ์ด ์‰ฝ๊ธฐ ๋•Œ๋ฌธ์— ์„ค๊ณ„๋ฅผ ์œ ์—ฐํ•˜๊ฒŒ ๋งŒ๋“ ๋‹ค. ๋”ฐ๋ผ์„œ ์ฝ”๋“œ ์žฌ์‚ฌ์šฉ์„ ์œ„ํ•ด์„œ๋Š” ์ƒ์†๋ณด๋‹ค๋Š” ํ•ฉ์„ฑ์„ ์„ ํ˜ธํ•˜๋Š” ๊ฒƒ์ด ๋” ์ข‹์€ ๋ฐฉ๋ฒ•์ด๋‹ค. 

 

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