我有两个对象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也具有相似的结构。
最佳答案
我想我缺少了一些东西。您是否考虑过抽象父类?