File tree 1 file changed +51
-0
lines changed
Roadmap/26 - SOLID SRP/javascript
1 file changed +51
-0
lines changed Original file line number Diff line number Diff line change
1
+ // ** EJERCICIO
2
+
3
+ // correcta
4
+
5
+ const basededatos = [ 'Pepe' , 'Pepa' ]
6
+
7
+ class User {
8
+ constructor ( name , email ) {
9
+ this . name = name ;
10
+ this . email = email ;
11
+ }
12
+
13
+ getUserData ( ) {
14
+ return `Name: ${ this . name } , Email: ${ this . email } ` ;
15
+ }
16
+ }
17
+
18
+ class UserRepository {
19
+ save ( user ) {
20
+ basededatos . push ( user . name )
21
+ }
22
+ }
23
+
24
+ const user = new User ( 'Bernat' , '[email protected] ' ) ;
25
+ console . log ( user . getUserData ( ) ) ;
26
+
27
+ const userRepository = new UserRepository ( ) ;
28
+ userRepository . save ( user ) ;
29
+ console . log ( basededatos )
30
+
31
+ // incorrecta
32
+
33
+ class User2 {
34
+ constructor ( name , email ) {
35
+ this . name = name ;
36
+ this . email = email ;
37
+ }
38
+
39
+ getUserData ( ) {
40
+ return `Name: ${ this . name } , Email: ${ this . email } ` ;
41
+ }
42
+
43
+ saveToDatabase ( ) {
44
+ basededatos . push ( user2 . name )
45
+ }
46
+ }
47
+
48
+ // Uso
49
+ const user2 = new User2 ( 'Bernat' , '[email protected] ' ) ;
50
+ console . log ( user2 . getUserData ( ) ) ;
51
+ user2 . saveToDatabase ( ) ;
You can’t perform that action at this time.
0 commit comments