My current Person class looks like this:
class Person {
constructor(name, age, gender, interests) {
Object.assign(this, {name, age, gender, interests});
}
}
I have also created a sub-class Teacher which inherits properties from the Person class:
class Teacher extends Person {
constructor(name, age, gender, interests, subject, grade) {
super(name, age, gender, interests);
Object.assign(this, {subject, grade});
}
}
However, I am now wondering about creating a new sub-class that does not inherit all properties from the Person class. For instance, I do not want to include the interests property. Would it be correct to exclude it like this:
class Student extends Person {
constructor(name, age, gender, height, weight) {
super(name, age, gender); // I chose not to include the interests property here
Object.assign(this, {height, weight});
}
}
As someone who is still learning, I am unsure if this approach is considered best practice. Thank you and have a wonderful day!