关于代码重构:问题如下
各个科目都对应一个“考试”的实体bean,各个对象里部分属性是一致的,也存在不同的属性。经常遇到的情况是要写好几套代码。
如下面的代码片段
if ("1".equals(subjectCode)) {
LogUtil.info("获取数学");
TestM testM = new TestM();
testM.setTeachingCode(teachingVersionCode);
testM.setGradeCode(gradeCode);
testM.setTermCode(Integer.valueOf(termCode));
testM.setQuesTestTypeCode(Integer.valueOf(testTypeCode));
List<TestM> resultList = testService.getTestMList(testM,pageNo);
int pageCount = testService.getPaperMCount(testM);
}
if ("2".equals(subjectCode)) {
LogUtil.info("获取英语");
TestE testE = new TestE();
testE.setTeachingCode(teachingVersionCode);
testE.setGradeCode(gradeCode);
testE.setTerECode(Integer.valueOf(terECode));
testE.setQuesTestTypeCode(Integer.valueOf(testTypeCode));
List<TestE> resultList = testService.getTestEList(testE,pageNo);
int pageCount = testService.getPaperECount(testE);
}
if ("3".equals(subjectCode)) {
LogUtil.info("获取语文");
TestC testC = new TestC();
testC.setTeachingCode(teachingVersionCode);
testC.setGradeCode(gradeCode);
testC.setTerCCode(Integer.valueOf(terCCode));
testC.setQuesTestTypeCode(Integer.valueOf(testTypeCode));
List<TestC> resultList = testService.getTestCList(testC,pageNo);
int pageCount = testService.getPaperCCount(testC);
}
请教如何进行优化会比较好一点?