I have to manage dues for customers. I made a class named Due. It stores dues for two types of customers X,Y. It goes like this.
public abstract class Due {
private CustomerType customerType; //can be either X or Y
protected DueType dueType;
private String dueId;
private BigDecimal dueAmount;
private Date dueDate;
public Due(CustomerType type) {
this.customerType = type;
}
//getters , setters goes here.
}
Also DueType are different for both X and Y. Thus I have made an interface named DueType and enums XDueType, YDueType implements it.
public interface DueType {
}
public enum XDueType implements DueType {
A, B;
}
public enum YDueType implements DueType {
C, D;
}
And i have two different classes, each specifically for X's and Y's due. Like this
public class XDue extends Due {
public XDue() {
super(CustomerType.X);
}
public XDueType getDueType() {
return (XDueType) this.dueType;
}
}
public class YDue extends Due {
public YDue() {
super(CustomerType.Y);
}
public YDueType getDueType() {
return (YDueType) this.dueType;
}
}
I have to do a lot of operations on Due irrespective of its type (These operations will be same for XDue or YDue).
My question is should I use inheritance here like above or not. I could have made just one class Due only. That could have simply done the job for me. But the former method appears like more semantically correct to me. Also, going forward XDue, YDue can become less similar. Thus I think its better to keep them separate from now. Am I correct?