Last active
July 29, 2018 15:45
-
-
Save raulmoyareyes/7aedb956d119066c88d945f044d424d0 to your computer and use it in GitHub Desktop.
Open / Closed Principle
This file contains hidden or 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
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