Skip to content

Instantly share code, notes, and snippets.

@raulmoyareyes
Last active July 29, 2018 15:45
Show Gist options
  • Save raulmoyareyes/7aedb956d119066c88d945f044d424d0 to your computer and use it in GitHub Desktop.
Save raulmoyareyes/7aedb956d119066c88d945f044d424d0 to your computer and use it in GitHub Desktop.
Open / Closed Principle
class Printable {
function print() {
// ...
}
}
class Pdf extends Printable {
constructor(name, size) {
super();
this.name = name;
this.size = size;
}
// Override
function print() {
// ...
}
}
class Png extends Printable {
constructor(name) {
super();
this.name = name;
}
// Override
function print() {
// ...
}
}
class Printer {
function printFile(file) {
file.print();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment