如何删除实体和Dto类中的重复字段?

时间:2019-05-30 07:12:20

标签: java hibernate architecture

假设我具有下一个类结构:

@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 ...
}

我认为这不是设计合理的类结构,因为我在每个类中重复了相同的货币字段。此外,如果必须添加一个新的货币字段,则必须将其添加到每个类中。你能建议我替代类结构吗?

0 个答案:

没有答案