Skip to content

Commit

Permalink
Merge pull request mouredev#4576 from bernatcs/main
Browse files Browse the repository at this point in the history
#26 - javascript
  • Loading branch information
Roswell468 authored Jun 26, 2024
2 parents 255e9ee + 7dad84b commit 3ffddfc
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions Roadmap/26 - SOLID SRP/javascript/bernatcs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// ** EJERCICIO

// correcta

const basededatos = ['Pepe', 'Pepa']

class User {
constructor(name, email) {
this.name = name;
this.email = email;
}

getUserData() {
return `Name: ${this.name}, Email: ${this.email}`;
}
}

class UserRepository {
save(user) {
basededatos.push(user.name)
}
}

const user = new User('Bernat', '[email protected]');
console.log(user.getUserData());

const userRepository = new UserRepository();
userRepository.save(user);
console.log(basededatos)

// incorrecta

class User2 {
constructor(name, email) {
this.name = name;
this.email = email;
}

getUserData() {
return `Name: ${this.name}, Email: ${this.email}`;
}

saveToDatabase() {
basededatos.push(user2.name)
}
}

// Uso
const user2 = new User2('Bernat', '[email protected]');
console.log(user2.getUserData());
user2.saveToDatabase();

0 comments on commit 3ffddfc

Please sign in to comment.