【发布时间】:2019-01-30 21:11:18
【问题描述】:
我想通过 uml/class-diagram 编写 java 代码。但我不确定它或如何为关系 0..1 到 0..1 编写它
我没有找到任何关于这种关系的信息。
1 到 0..1 是可能的,我知道如何创建它。 这是我的类图,关系为 0..1 到 0..1:
我为它写了这段代码。
public class IssueWithBankStuff {
Iban Iban;
Bic bic;
Customer customer;
Date contractIban;
IssueWithOtherStuff other;
public IssueWithBankStuff() {
}
public ContractForm getContractForm() {
return other.gethContractForm();
}
public void setContractForm(ContractForm contractForm) {
other.gethContractForm(contractForm);
}
public isHolding() {
return other.isHolding();
}
public void setHolding(Boolean hold) {
other.setHolding(hold);
}
public isGeneralCorperateForm() {
return other.isGeneralCorperateForm();
}
public void setHolding(Boolean generalCorperateForm) {
other.setGeneralCorperateForm(generalCorperateForm);
}
public getStartDate() {
return other.getStartDate();
}
public void setContractForm(Date startDate) {
other.setStartDate(startDate);
}
//class specific getters and setters
}
public IssueWithOtherStuff {
ContractForm contractForm;
Boolean holding;
Boolean generalCorperateForm
Date startDate;
IssueWithBankStuff iban;
public IssueWithOtherStuff () {
}
public void setIban(Iban ib) {
iban.setIban(ib);
}
public Iban getIban () {
return iban.getIban();
}
public void setBic(Bic bic) {
iban.setBic(bic);
}
public Bic getBic () {
return iban.getBic();
}
public void setCustomer(Customer customer) {
iban.setCustomer(customer);
}
public Customer getCustomer () {
return iban.getCustomer();
}
public void setContractIban(Date contractIban) {
iban.setContractIban(contractIban);
}
public Date getContractIban () {
return iban.getContractIban();
}
//getters and setters
}
【问题讨论】:
-
为强制关系 [1] 编写代码比为选项关系 [0..1] 编写代码要困难得多。您编写的代码是可选的,因为我可以创建
IssueWithOtherStuff而将字段iban留空。 -
这两个类都应该是可选的。 :)
标签: java class uml class-diagram multiplicity