Skip to content

Instantly share code, notes, and snippets.

@yeisoncruz16
Created October 10, 2020 02:08
Show Gist options
  • Save yeisoncruz16/9fc66aa473f359c25de949d034a93508 to your computer and use it in GitHub Desktop.
Save yeisoncruz16/9fc66aa473f359c25de949d034a93508 to your computer and use it in GitHub Desktop.
Ejemplo de DRY usando Javascript
// ----> 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