Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* S.O.L.I.D. */
- /* Single responsiblitiy prinicple
- - everything should only have one reason to change */
- /* BAD */
- class UserSettings {
- constructor(user) {
- this.user = user
- }
- changeSettings(settings) {
- if (this.verifyCredentials()) {
- //...
- }
- }
- verifyCredentials() {
- //...
- }
- }
- /* GOOD */
- class UserAuth {
- constructor(user) {
- this.user = user
- }
- verifyCredentials() {
- //...
- }
- }
- class UserSettings {
- constructor(user) {
- this.user = user;
- this.auth = new UserAuth(user);
- }
- changeSettings(settings) {
- if (this.auth.verifyCredentials()) {
- //...
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment