我是 UML 图的新手,并且正在阅读有关它的书。那里有一个类图,如下所示:
它说,
The implication of a one to one association is that whenever you create an
instance of one of the classes, you must simultaneously create an instance
of the other, and when you delete one you must delete the other.
我的问题是,我们真的必须这样做吗?我们不能将“null”作为其中之一的值吗?例如,我想这个图的java代码如下,当我想创建一个公司项目时,我可以给null作为参数。我错了吗?或者这是一段糟糕或错误的代码?
public class Company{
. . .
private BoardOfDirectors director;
public Company(BoardOfDirectors director){
this.director=director;
}
. . .
}
public class BoardOfDirectors{
. . .
private Company company;
public BoardOfDirectors(Company company){
this.company=company;
}
. . .
}
谢谢你。