我有兩個對象CreateDocumentHeader和RetrieveDocumentHeader,它們具有非常相似的結構。我正在閱讀每個對象並填充一個DTO。我不想爲每個對象創建不同的方法。我如何編寫一個單一的方法來填充它們。這是兩個類。用於填充不同對象的常見方法類似結構
public class CreateDocumentHeaderType {
protected CreateAdminRecordType administrativeRecord;
protected CreateControlRecordType controlRecord;
public CreateAdminRecordType getAdministrativeRecord() {
return administrativeRecord;
}
public void setAdministrativeRecord(CreateAdminRecordType value) {
this.administrativeRecord = value;
}
public CreateControlRecordType getControlRecord() {
return controlRecord;
}
public void setControlRecord(CreateControlRecordType value) {
this.controlRecord = value;
}
}
public class RetrieveDocumentHeaderType {
protected RetrieveAdminRecordType administrativeRecord;
protected RetrieveControlRecordType controlRecord;
public RetrieveAdminRecordType getAdministrativeRecord() {
return administrativeRecord;
}
public void setAdministrativeRecord(RetrieveAdminRecordType value) {
this.administrativeRecord = value;
}
public RetrieveControlRecordType getControlRecord() {
return controlRecord;
}
public void setControlRecord(RetrieveControlRecordType value) {
this.controlRecord = value;
}
}
這兩個版本的AdminstrativeRecord和ControlRecord也有類似的結構。
感謝您的回覆,我真的很抱歉,我錯過了一點。 CreateDocumentHeaderType和RetrieveDocumentHeaderType等是JAXB生成的文件,所以我想我不能改變它們來實現或擴展任何接口或類。我很抱歉這個錯過。 – Ravi 2011-02-25 06:04:23