Java类关系和ORM

时间:2016-02-23 11:48:18

标签: java relationship

我使用以下类具有这种简单的登录注册功能。

用户类:

public class User implements Serializable {
    private int userId;
    private String username;
    private String password;

    public User() {
        userId = 0;
        username = "";
        password = "";
    }

    // public set-get methods here
}

验证类:

public class Verification implements Serializable {
    private int userId;
    private String code;
    private long expirationDate; // millis

    public Verification() {
        userId = 0;
        code = "";
        expirationDate = 0;
    }

    public void setUserId(int Id) {
        userId = Id;
    }

    public void setUserId(User user) {
        userId = user.getUserId();
    }

    // the rest of set-get methods here
}

我想确认上述关系是否被视为依赖?还是协会?

另外,我在ORM中使用这个类。省略一个setUserId()重载方法会弄乱它们之间的关系(如果有的话)?谢谢。

2 个答案:

答案 0 :(得分:0)

您给出的示例描述了依赖性。
作为参考,您可以访问以下链接 - :

https://nirajrules.wordpress.com/2011/07/15/association-vs-dependency-vs-aggregation-vs-composition/

答案 1 :(得分:0)

我会说Verification和User之间存在依赖关系,因为您可以将User引用传递给Verification方法(它使用该引用并依赖于它),但是Verification实例不会对User实例进行OWN引用,相反,它消耗一个。

相关问题