Spot the SRP Violation
Find which SOLID principle this User class breaks at an introductory level.
Codejavascript
class User {
constructor(name, email) {
this.name = name;
this.email = email;
}
getName() {
return this.name;
}
// persistence logic
saveToDatabase() {
const db = connectToDatabase();
db.insert('users', { name: this.name, email: this.email });
}
// formatting/reporting logic
generateReport() {
return `<html><body>User: ${this.name}</body></html>`;
}
}Which SOLID principle does this class violate, and how should it be fixed?