Skip to content

Instantly share code, notes, and snippets.

@mcsee
Last active May 31, 2022 00:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mcsee/b6550c193e41862ed8a84cbe885d989d to your computer and use it in GitHub Desktop.
Save mcsee/b6550c193e41862ed8a84cbe885d989d to your computer and use it in GitHub Desktop.
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