Class UserSession

java.lang.Object
angry3vilbot.bankingapp.UserSession

public class UserSession extends Object
UserSession class to manage user session data. This class is implemented as a Singleton to ensure that only one instance of the session exists throughout the application. It stores the user information and provides methods to get and set the user. It also provides a method to clear the session data when the user logs out.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private static UserSession
    The singleton instance of UserSession.
    private User
    The User object that contains user information.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
    Private constructor to prevent instantiation
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Clears the session data This method is used after a user logs out to clear the user information from the session.
    Get the singleton instance of UserSession This method is synchronized to ensure thread safety when accessing the singleton instance.
    Gets the User object that represents the current user
    void
    setUser(User user)
    Sets the new User object

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • instance

      private static UserSession instance
      The singleton instance of UserSession.
    • user

      private User user
      The User object that contains user information.
  • Constructor Details

    • UserSession

      private UserSession()
      Private constructor to prevent instantiation
  • Method Details

    • getInstance

      public static UserSession getInstance()
      Get the singleton instance of UserSession This method is synchronized to ensure thread safety when accessing the singleton instance.
      Returns:
      the singleton instance of UserSession
    • getUser

      public User getUser()
      Gets the User object that represents the current user
      Returns:
      the User object
    • setUser

      public void setUser(User user)
      Sets the new User object
      Parameters:
      user - the User object to set
    • clearSession

      public void clearSession()
      Clears the session data This method is used after a user logs out to clear the user information from the session.