1

I am trying to write a client for a restful service. I am confused in designing the models. Below are the details:

I have a Model named UnicastMessageRequest, it's definition is like this:

    public class/abstract-class/interface UnicastMessageRequest
    {
        public string tId { get; set; }
        public IDictionary<string, object> tVariables { get; set; }
        [JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))]
        public CommunicationMedium communicationMedium { get; set; }
        public IList<MessageAttachment> messageAttachments { get; set; }
        public string to { get; set; }
    }

I am not sure about making this class as a concrete class or abstract class or an interface, so right now I wrote the type as class/abstract class/interface.

This above model has the properties which I need to send as a body in an HTTP post request.

Now, I am performing different functions like sending email, sending SMS or sending WhatsApp message by hitting the same HTTP end point which needs the above defined UnicastMessageRequest model as the body of the request.

So, for convenience, I was thinking to write Wrapper data models for Email request, WhatsApp request and SMS request.

properties like tId, tVariables communicationMedium and to is necessary for all the request body, but messageAttachment isn't necessary.

Example of a EmailRequest model:

public class EmailRequest
{
    public string tId { get; set; }
    public IDictionary<string, object> tVariables { get; set; }
    [JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))]
    public CommunicationMedium communicationMedium { get; set; }
    public IList<MessageAttachment> messageAttachments { get; set; }
    public string to { get; set; }
}

Example of a SMSRequest model:

public class EmailRequest
{
    public string tId { get; set; }
    public IDictionary<string, object> tVariables { get; set; }
    [JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))]
    public CommunicationMedium communicationMedium { get; set; }
    public string to { get; set; }
}

Here messageAttachments isn't required at all. Similarly, I have a WhatsAppRequest model. All these request model needs to be finally converted into the UnicastMessageRequest so that they can call a common API something like:

SendUnicastMessage(UnicastMessageRequest request)

How to design it the best way?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.