Created
October 10, 2020 02:08
-
-
Save yeisoncruz16/9fc66aa473f359c25de949d034a93508 to your computer and use it in GitHub Desktop.
Ejemplo de DRY usando Javascript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ----> Design Principles | |
// DRY | |
// 0 | |
console.log("Don’t Repeat Yourself"); | |
// 1 | |
console.log("Encapsulate What Varies"); | |
class Tax { | |
calculteTax(){ | |
let tax = 0 //complex logic for tax; | |
if(country == 'us'){ | |
tax = 10; | |
} else { | |
tax = 20; | |
} | |
this.calculateDb(); | |
this.calculateIP(); | |
} | |
calculateDb(){ | |
// DB | |
} | |
calculateIP(){ | |
// IP | |
} | |
} | |
class Order { | |
constructor(tax){ | |
this.tax = tax; | |
} | |
calculateTotal(){ | |
let subTotal = 10; | |
// complex | |
this.tax.calculteTax(); | |
return subTotal + tax; | |
} | |
} | |
// 2 | |
console.log("Encapsulation on a method level"); | |
// 3 | |
console.log("Encapsulation on a class level"); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment