Skip to content

Commit cbdf00c

Browse files
committed
Ejercicio #23 completado
1 parent 81a5fab commit cbdf00c

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

Roadmap/23 - SINGLETON/java/simonguzman.java

+52
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,60 @@
1+
12
public class simonguzman {
23
public static void main(String[] args) {
34
genericSingleton();
5+
additionalExercise();
6+
}
7+
/**************************** Ejercicio adicional ****************************/
8+
public static void additionalExercise(){
9+
UserSession session = UserSession.getUserInstance();
10+
session.assignUser("001", "Simon Guzman", "sguzman", "[email protected]");
11+
System.out.println(session.getUserData());
12+
session.deleteSession();
13+
System.out.println(session.getClass());
14+
}
15+
16+
public static class UserSession{
17+
private static UserSession instance;
18+
19+
private String id;
20+
private String name;
21+
private String userName;
22+
private String email;
23+
24+
private UserSession(){
25+
26+
}
27+
28+
public static UserSession getUserInstance(){
29+
if(instance == null){
30+
instance = new UserSession();
31+
}
32+
return instance;
33+
}
34+
35+
public void assignUser(String id, String name, String userName, String email){
36+
this.id = id;
37+
this.name = name;
38+
this.userName = userName;
39+
this.email = email;
40+
}
41+
42+
public String getUserData(){
43+
if (id == null){
44+
return "No hay usuarios en la sesion";
45+
}
46+
return "ID: "+id+" ,username: " + userName + " ,name: " + name + " ,email: " + email;
47+
}
48+
49+
public void deleteSession(){
50+
id = null;
51+
name = null;
52+
userName = null;
53+
email = null;
54+
}
455
}
556

57+
/**************************** Ejemplo de singleton ****************************/
658
public static void genericSingleton(){
759
Singleton singleton = Singleton.getInstance();
860
singleton.showMessage();

0 commit comments

Comments
 (0)