Skip to content

Latest commit

 

History

History
29 lines (24 loc) · 553 Bytes

dont-repeat-yourself.md

File metadata and controls

29 lines (24 loc) · 553 Bytes

Don't Repeat Yourself

Code violating the DRY principle:

class Employee {
    calculateSalaryNet() {
        return this.hoursWorked * this.hourlyWage;
    }

    calculateSalaryGross() {
        return this.hoursWorked * this.hourlyWage + TAX;
    }
}

Fixed code:

class Employee {
    calculateSalaryNet() {
        return this.hoursWorked * this.hourlyWage;
    }

    calculateSalaryGross() {
        return this.calculateSalaryNet() + TAX;
    }
}