假设我具有下一个类结构:
@MappedSuperclass
public abstract class Identifiable<T> {
@Id
@GeneratedValue
private T id;
//getters & setters
}
@Entity
@Table(name="purse")
public class Purse extends Identifiable<Long> {
private Integer ruAmount;
private Integer usdAmount;
private Integer eurAmount;
... // getters and setters with hibernate @Column annotations
}
@Entity
@Table(name="credit_card")
public class CreditCard extends Identifiable<Long> {
private Integer ruAmount;
private Integer usdAmount;
private Integer eurAmount;
... // getters and setters with hibernate @Column annotations
}
public class CreditCardDto {
private Integer ruAmount;
private Integer usdAmount;
private Integer eurAmount;
// getters and setters ...
}
我认为这不是设计合理的类结构,因为我在每个类中重复了相同的货币字段。此外,如果必须添加一个新的货币字段,则必须将其添加到每个类中。你能建议我替代类结构吗?