Skip to content

Instantly share code, notes, and snippets.

@mcsee
Last active August 21, 2023 14:01
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/bd0982f4c86a3523cd5a956196214b9c to your computer and use it in GitHub Desktop.
Save mcsee/bd0982f4c86a3523cd5a956196214b9c 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 {
constructor(userscore) {
this._userscore = userscore;
}
fullname() {
return `${this._userscore.name()} ${this._userscore.lastname()}`;
}
}
class CategoryCalculator{
constructor(userscore1) {
this._userscore = userscore1;
}
display() {
return this._userscore.points() > 70 ? 'A' : 'B';
}
}
let alice = new UserScore('Alice', 'Gray', 78);
const fullName = new FullNameFormatter(alice).fullname();
const category = new CategoryCalculator(alice).display();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment