Skip to content

Instantly share code, notes, and snippets.

@raulmoyareyes
Created July 29, 2018 15:37
Show Gist options
  • Save raulmoyareyes/b5912a99f1cc8e521e458fcd479e7a14 to your computer and use it in GitHub Desktop.
Save raulmoyareyes/b5912a99f1cc8e521e458fcd479e7a14 to your computer and use it in GitHub Desktop.
[ Wrong ] - Open / Closed Principle
class Pdf {
constructor(name, size) {
this.name = name;
this.size = size;
}
// ...
}
class Png {
constructor(name) {
this.name = name;
}
// ...
}
class Printer {
function printFile(file) {
if (file instanceof Pdf) {
// Print Pdf...
} else if (file instanceof Png) {
// Print Png...
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment