Package io.github.astrapi69.design.pattern.observer.chat
package io.github.astrapi69.design.pattern.observer.chat
Provides classes and interfaces for implementing a chat application using the observer design
pattern
The chat package includes implementations of chat rooms, users, and messages, all of which interact through the observer pattern This package demonstrates how to structure a chat system where users can send and receive messages, and how those messages are propagated to all participants in the chat room.
The key components of this package include:
ChatRoom
- Represents a chat room where users can exchange messagesChatRoomUser
- Represents a user participating in a chat roomMessage
- An interface for messages sent within the chat roomStringMessage
- A concrete implementation ofMessage
for text-based messagesUser
- Represents a user entity in the chat system
The observer design pattern allows the chat application to notify all users in a chat room when a new message is received This package demonstrates a flexible and extensible way to implement such functionality using Java.
-
ClassDescriptionThe class
ChatMessage
represents a message in a chat application It implements theMessage
interface and is serializableThe classChatRoom
represents a chat room where users can send and receive messages It extendsAbstractSubject
and implementsSubject
,Room
, andSerializable
ChatRoomService<M extends Message<?>>The classChatRoomService
manages the creation and retrieval of chat rooms It provides a way to obtain aChatRoom
based on an observable message and a room nameChatRoomUser<M extends Message<?>>The classChatRoomUser
represents a user in a chat room who can send and receive messages This class implementsObserver
to observe messages in the chat room,ActionCommand
to define actions when a message is received, andSerializable
for serialization supportInvitation<M extends Message<?>>The InterfaceInvitation
represents an invitation to join a chat room It defines the methods to retrieve the sender, recipient, and the room associated with the invitation, as well as methods to check if the invitation has been accepted and if the denial is visible to the senderIUser<U>The interfaceIUser
represents a user in a chat application It provides methods to manage the user's identity, including getting and setting the application user, retrieving the user's unique identifier, and obtaining the user's nameMessage<T>The interfaceMessage
represents a message that can be sent in a chat application It provides methods for getting and setting the value of the messageThe classMessageRoomModelBean
represents a model for a message in a chat room It includes details such as the chat room name, the user who sent the message, the message content, and any associated data, as well as the date the message was createdThe interfaceRoom
represents a chat room in which users can participate It provides methods to retrieve the list of users in the chat room, the history of messages sent in the room, and to check whether the room is secureThe classStringMessage
represents a message that contains a string value It implements theMessage
interface and provides methods to get and set the string value