forked from mouredev/roadmap-retos-programacion
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
81a5fab
commit cbdf00c
Showing
1 changed file
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,60 @@ | ||
|
||
public class simonguzman { | ||
public static void main(String[] args) { | ||
genericSingleton(); | ||
additionalExercise(); | ||
} | ||
/**************************** Ejercicio adicional ****************************/ | ||
public static void additionalExercise(){ | ||
UserSession session = UserSession.getUserInstance(); | ||
session.assignUser("001", "Simon Guzman", "sguzman", "[email protected]"); | ||
System.out.println(session.getUserData()); | ||
session.deleteSession(); | ||
System.out.println(session.getClass()); | ||
} | ||
|
||
public static class UserSession{ | ||
private static UserSession instance; | ||
|
||
private String id; | ||
private String name; | ||
private String userName; | ||
private String email; | ||
|
||
private UserSession(){ | ||
|
||
} | ||
|
||
public static UserSession getUserInstance(){ | ||
if(instance == null){ | ||
instance = new UserSession(); | ||
} | ||
return instance; | ||
} | ||
|
||
public void assignUser(String id, String name, String userName, String email){ | ||
this.id = id; | ||
this.name = name; | ||
this.userName = userName; | ||
this.email = email; | ||
} | ||
|
||
public String getUserData(){ | ||
if (id == null){ | ||
return "No hay usuarios en la sesion"; | ||
} | ||
return "ID: "+id+" ,username: " + userName + " ,name: " + name + " ,email: " + email; | ||
} | ||
|
||
public void deleteSession(){ | ||
id = null; | ||
name = null; | ||
userName = null; | ||
email = null; | ||
} | ||
} | ||
|
||
/**************************** Ejemplo de singleton ****************************/ | ||
public static void genericSingleton(){ | ||
Singleton singleton = Singleton.getInstance(); | ||
singleton.showMessage(); | ||
|