Last active
May 31, 2022 00:42
-
-
Save mcsee/b6550c193e41862ed8a84cbe885d989d to your computer and use it in GitHub Desktop.
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
class UserScore { | |
// This is anemic class and should have better protocol | |
constructor(name, lastname, points) { | |
this._name = name; | |
this._lastname = lastname; | |
this._points = points; | |
} | |
name() { | |
return this._name; | |
} | |
lastname() { | |
return this._lastname; | |
} | |
points() { | |
return this._points; | |
} | |
} | |
class FullNameFormatter { | |
fullname(userscore) { | |
return `${userscore.name()} ${userscore.lastname()}`; | |
} | |
} | |
class CategoryCalculator { | |
display(userscore) { | |
return userscore.points() > 70 ? 'A' : 'B'; | |
} | |
} | |
let alice = new UserScore('Alice', 'Gray', 78); | |
const fullName = new FullNameFormatter().fullname(alice); | |
const category = new CategoryCalculator().display(alice); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment