java.lang.Object
io.github.astrapi69.design.pattern.observer.chat.ChatRoomUser<M>
Type Parameters:
M - the generic type of the message that will be sent and observed in the chat room
All Implemented Interfaces:
ActionCommand, Observer<M>, Serializable

public abstract class ChatRoomUser<M extends Message<?>> extends Object implements Observer<M>, ActionCommand, Serializable
The class ChatRoomUser represents a user in a chat room who can send and receive messages This class implements Observer to observe messages in the chat room, ActionCommand to define actions when a message is received, and Serializable for serialization support
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected ChatRoom<M>
    The chat room (subject) that this user is part of
  • Constructor Summary

    Constructors
    Constructor
    Description
    ChatRoomUser(ChatRoom<M> room, IUser<?> user)
    Instantiates a new chat room user
  • Method Summary

    Modifier and Type
    Method
    Description
    Gets the observable message currently observed by this user
    Gets the user associated with this chat room user
    void
    send(M message)
    Sends the given message to the chat room
    void
    update(M observable)
    This method is called to notify the observer of changes in the observable object Implementing classes should define the specific behavior that occurs when the observable object changes

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface io.github.astrapi69.design.pattern.observer.api.ActionCommand

    execute
  • Field Details

    • subject

      protected ChatRoom<M extends Message<?>> subject
      The chat room (subject) that this user is part of
  • Constructor Details

    • ChatRoomUser

      public ChatRoomUser(ChatRoom<M> room, IUser<?> user)
      Instantiates a new chat room user
      Parameters:
      room - the chat room (subject) that this user is part of
      user - the user associated with this chat room user
  • Method Details

    • getObservable

      public M getObservable()
      Gets the observable message currently observed by this user
      Returns:
      the observable message
    • getUser

      public IUser<?> getUser()
      Gets the user associated with this chat room user
      Returns:
      the user
    • send

      public void send(M message)
      Sends the given message to the chat room
      Parameters:
      message - the message to be sent
    • update

      public void update(M observable)
      This method is called to notify the observer of changes in the observable object Implementing classes should define the specific behavior that occurs when the observable object changes
      Specified by:
      update in interface Observer<M extends Message<?>>
      Parameters:
      observable - the observable object that has changed