Skip to content

Instantly share code, notes, and snippets.

@mcsee
Last active August 22, 2023 00:06
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/388923d775ca893eb1e6ca4c28c3287f to your computer and use it in GitHub Desktop.
Save mcsee/388923d775ca893eb1e6ca4c28c3287f to your computer and use it in GitHub Desktop.
class Teacher {
static getByID(id) {
// This is coupled to the database
// Thus violating separation of concerns
}
constructor(id, fullName) {
this.id = id;
this.fullName = fullName;
}
}
class School {
static getByID(id) {
// go to the coupled database
}
constructor(id, address) {
this.id = id;
this.address = address;
}
}
class Student {
constructor(firstName, lastName, id, teacherId, schoolId) {
this.firstName = firstName;
this.lastName = lastName;
this.id = id;
this.teacherId = teacherId;
this.schoolId = schoolId;
}
school() {
return School.getById(this.schoolId);
}
teacher() {
return Teacher.getById(this.teacherId);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment