I am trying to build a very basic instant messaging platform. I have three basic immutable types, and each of them has a subclass for dealing with CRUD (for SRP purposes, separating the class from the database logic).
Conversation:
public class Conversation
{
public uint Id { get; private set; }
public List<Participant> Participants { get; private set; }
public List<Message> Messages { get; private set; }
/* Some extra properties */
public Conversation(uint id, List<Participant> participants, List<Message> messages)
{
Id = id;
Participants = participants;
Messages = messages;
}
public static class CRUD
{
static void Create(...) {}
static void Read(...) {}
static void Update(...) {}
static void Delete(...) {}
}
}
Message:
public class Message
{
public uint Id { get; private set; }
public Conversation Conversation { get; private set; }
public Participant Sender { get; private set; }
public DateTime SendingTime { get; private set; }
public string Content { get; private set; }
/* Constructor */
/* CRUD */
}
Participant:
public class Participant
{
public Conversation Conversation { get; private set; }
public Employee Employee { get; private set; }
/* Constructor */
/* CRUD */
}
I thought Message.CRUD.Read(...)
should get the messages from the database, and Participant.CRUD.Read(...)
should get the participant from the database. But then What should Conversation.CRUD.Read(...)
read and what should it return?
I mean, should it get from the database all the information about the conversation that has no class representation in the code (i.e. not Message
and Participant
), and then, should it return a non-complete object of Conversation
with some null
s or should it do something else? What is the best practice here? Is there any?