I am writing a wrapper for a REST API and I have run into something I have never had to ask myself before.
This API is for E-Commerce transactions, it has SALE and RETURN endpoints (and some other endpoints that aren't critical to this discussion).
The SALE and RETURN requests are nearly identical, with the exception that the SALE request has an additional property.
public class ReturnRequest
{
[JsonProperty("cashier_id")]
public string CashierId { get; set; }
[JsonProperty("amount")]
public decimal Amount { get; set; }
[JsonProperty("pos_id")]
public CustomClass PosId { get; set; }
}
public class SaleRequest
{
[JsonProperty("cashier_id")]
public string CashierId { get; set; }
[JsonProperty("amount")]
public decimal Amount { get; set; }
[JsonProperty("pos_id")]
public CustomClass PosId { get; set; }
[JsonProperty("zip_code")]
public string ZipCode { get; set; }
}
Originally I just had the SALE request POCO inherit the RETURN request POCO:
public class ReturnRequest
{
[JsonProperty("cashier_id")]
public string CashierId { get; set; }
[JsonProperty("amount")]
public decimal Amount { get; set; }
[JsonProperty("pos_id")]
public CustomClass PosId { get; set; }
}
public class SaleRequest : ReturnRequest
{
[JsonProperty("zip_code")]
public string ZipCode { get; set; }
}
But to me that didn't seem very intuitive or clear (SALE and RETURN are different things, why would one inherit another?)
I then decided to put the common properties into a base abstract class:
public abstract class BaseRequest
{
[JsonProperty("cashier_id")]
public string CashierId { get; set; }
[JsonProperty("amount")]
public decimal Amount { get; set; }
[JsonProperty("pos_id")]
public CustomClass PosId { get; set; }
}
public class ReturnRequest : BaseRequest
{
}
public class SaleRequest : BaseRequest
{
[JsonProperty("zip_code")]
public string ZipCode { get; set; }
}
But then that leaves me with a class that is essentially the same thing as the BaseRequest.
At first I justified this because I wanted the classes to be straightforward and verbose. It creates a clear difference between the classes and I can modify the SALE or RETURN without worrying about the other (or even the base classs).
However now I am wondering if I am thinking through this wrong, is having essentially a blank class a bad idea?
EDIT: I changed the property names and types up a bit to more closely represent some of the types of properties.