Communication System

Difficulty: MEDIUMCategory: LLDFrequency: 1Asked On 2025-03-29

Problem Statement

Design an object-oriented system for a basic communication platform that allows users to send and receive messages, both in one-on-one chats and in group chats.


✅ Functional Requirements:

1.User Management
•Users should be able to register and login.
•Each user has a unique ID, name, and status (e.g., online/offline).
2.One-to-One Messaging
•A user can send messages to another user.
•Messages should be delivered in order.
•Users can see their chat history with another user.
3.Group Messaging
•A user can create a group and add/remove users.
•Group members can send messages to the group.
•All members should receive group messages in the correct order.
4.Message Features
•Messages can be text only (for now).
•Messages should have metadata: sender, timestamp, and recipient (user or group).
•Message read status should be tracked per recipient (optional stretch).
5.Chat History
•Users can view their chat history (with individuals or groups).


🧱 Classes to Consider:

You are expected to model classes such as:

•User
•Message
•Chat
•GroupChat
•MessageService or ChatManager


Think about:

•Relationships: one-to-one, one-to-many
•Inheritance or composition
•Data structures to store messages and participants


🧠 Constraints:

•Assume this is an in-memory design (no database).
•No concurrency or delivery failures.
•Message ordering and delivery should be consistent.
•You are not responsible for network-level transmission.


🚫 Out of Scope (for LLD):

•Database persistence
•Server deployment
•Real-time notifications (e.g., push/websockets)
•File or multimedia messaging


🧪 Example Use Case:

1plaintext 2CopyEdit 3- User A sends "Hello" to User B 4- User B replies "Hi" 5- User A creates a group "Friends" and adds B and C 6- A sends "Hey everyone" to the group 7- C sends "Hi A" to the group 8- All group members can see the chat history


Solution

Comments