tonykang22 / study

0 stars 0 forks source link

[Refactoring] 냄새 24. 주석 #42

Open leeyuunsung opened 2 years ago

leeyuunsung commented 2 years ago

냄새 24. 주석 (Comments)


리팩토링 43. 어서션 추가하기 (Introduce Assertion)

Before

public class Customer {
    private Double discountRate;

    public double applyDiscount(double amount) {
        return (this.discountRate != null) ? amount - (this.discountRate * amount) : amount;
    }

    public Double getDiscountRate() {
        return discountRate;
    }

    public void setDiscountRate(Double discountRate) {
        this.discountRate = discountRate;
    }
}

After

public class Customer {
    private Double discountRate;

    public double applyDiscount(double amount) {
        return (this.discountRate != null) ? amount - (this.discountRate * amount) : amount;
    }

    public Double getDiscountRate() {
        return discountRate;
    }

    public void setDiscountRate(Double discountRate) {
        assert discountRate != null && discountRate > 0;
        this.discountRate = discountRate;
    }
}