写POJO或Utility的方法更好的方法?

时间:2018-01-12 07:09:16

标签: java performance methods pojo code-reuse

哪种方法更适合创建方法

1)在DataUtils.java类中创建静态方法

2)在pojo Claimheader.java类中创建方法。

我的问题是,如果我们在POJO类中创建一个方法,它将影响任何性能。

在我们的项目中,我们在POJO类中添加了许多方法,只有get方法。那么在POJO类中创建get方法是否合适?  或

在Utility类中创建方法。

我的老板说要在POJO类中创建get方法而不是在任何实用程序类中创建。

请建议我哪个是创建它的更好方法。我认为我是正确的,如果我在DataUtils.java中创建方法而不是在Pojo类中创建。

请参阅以下代码:

public class DataUtils {

    public static String getCurrentResp(Integer currentResp) {
        String val;

        switch (currentResp) {
        case 1:
            val = "Primary";
            break;
        case 2:
            val = "Secondary";
            break;
        case 3:
            val = "Tertiary";
            break;
        default:
            val = currentResp + "th Insurance";
            break;
        }

        return val;

    }
}

VS

@Entity
@Table(name = "claimheader")
@NamedQueries({
        @NamedQuery(name = "ClaimHeader.getClaimByClaimNo", query = "SELECT clmhead  FROM ClaimHeader  as clmhead WHERE clmhead.claimNo = :arg1 "),
        @NamedQuery(name = "claimHeader.GetUnPaidClaimByPatient", query = "SELECT clmhead  FROM ClaimHeader  as clmhead WHERE clmhead.insBalance > 0 and clmhead.patientCode = :arg1 "),
        @NamedQuery(name = "claimHeader.GetUnPaidClaimByPatientCode", query = "SELECT clmhead  FROM ClaimHeader  as clmhead WHERE (clmhead.billedAmount = clmhead.balanceAmount) and clmhead.patientCode = :arg1 "),
        @NamedQuery(name = "claimHeader.GetPaidClaimByPatientCode", query = "SELECT clmhead  FROM ClaimHeader  as clmhead WHERE (clmhead.balanceAmount = 0) and clmhead.patientCode = :arg1 "),
        @NamedQuery(name = "claimHeader.GetUnPaidAndPaidClaimByPatientCode", query = "SELECT clmhead  FROM ClaimHeader  as clmhead WHERE clmhead.patientCode = :arg1 ") })
public class ClaimHeader extends BaseEntityByCode {

    private static final long serialVersionUID = 1L;

    @Id
    @NotNull(message = "Claim No cannot be empty")
    private Integer claimNo;

    private Integer currentResp;


    public Integer getCurrentResp() {
        return currentResp;
    }

    public void setCurrentResp(Integer currentResp) {
        this.currentResp = currentResp;
    }

    public String getCurrentRespDesc() {

        String value = "";
        if (currentResp == null)
            return "";

        switch (currentResp) {
        case -1:
            value = "Patient";
            break;
        case 1:
            value = "Primary";
            break;
        case 2:
            value = "Secondary";
            break;
        case 3:
            value = "Tertiary";
            break;
        default:
            value = currentResp.toString() + "th Insurance";
            break;
        }

        return value;
    }

}

1 个答案:

答案 0 :(得分:0)

我会坚持你的老板。不是关于这里的表现的专业人士,但我认为这些都不会以相关的方式影响你的表现。

更重要的是代码逻辑本身。 Utils类应该为外部方法提供额外的便利函数(就像Integer.parseInt()方法或整个Apache Commons lib)。获取有关组件本身的信息是该对象逻辑的一部分,应放在其中。