Created
April 28, 2019 16:01
-
-
Save benfluleck/5486f1a476e197b7fdbba5066d6f504e to your computer and use it in GitHub Desktop.
Interface segregation principle
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
// bad | |
class Post { | |
constructor(){ | |
} | |
editPost(){ | |
console.log('Post edited') | |
} | |
createPost(){ | |
console.log('Post created') | |
} | |
deletePost(){ | |
console.log('Post created') | |
} | |
} | |
// moderators edit posts | |
// the moderator classes does not depend on the other functions | |
// but now it has access to the other methods | |
class Moderator extends Post () { | |
} | |
// good | |
class Post { | |
constructor(moderator){ | |
this.moderator = moderator | |
} | |
editPost(){ | |
if(this.moderator) { | |
console.log('Post edited') | |
} else { | |
console.log('Post denied') | |
} | |
} | |
createPost(){ | |
console.log('Post created') | |
} | |
deletePost(){ | |
console.log('Post created') | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment