Blog Stats
  • Posts - 179
  • Articles - 0
  • Comments - 51
  • Trackbacks - 3

 

Nasty legacy code

My current project is to maintain a range of application for a financial/insurance firm. Trying to sort out a bug in some nasty legacy-code (VB.NET) I just came across this piece of code:

If objDataReader("ID_QuestionType") = 1 Then ShowQuestion = ShowQuestionType1(ID_Question, ...)
If objDataReader("ID_QuestionType") = 2 Then ShowQuestion = ShowQuestionType2(ID_Question, ...)
If objDataReader("ID_QuestionType") = 3 Then ShowQuestion = ShowQuestionType3(ID_Question, ...)
If objDataReader("ID_QuestionType") = 4 Then ShowQuestion = ShowQuestionType4(ID_Question, ...)
If objDataReader("ID_QuestionType") = 5 Then ShowQuestion = ShowQuestionType5(ID_Question, ...)
If objDataReader("ID_QuestionType") = 6 Then ShowQuestion = ShowQuestionType6(ID_Question, ...)
If objDataReader("ID_QuestionType") = 7 Then ShowQuestion = ShowQuestionType7(ID_Question, ...)
If objDataReader("ID_QuestionType") = 8 Then ShowQuestion = ShowQuestionType8(ID_Question, ...)
If objDataReader("ID_QuestionType") = 9 Then ShowQuestion = ShowQuestionType9(ID_Question, ...)
If objDataReader("ID_QuestionType") = 10 Then ShowQuestion = ShowQuestionType10(ID_Question, ...)
If objDataReader("ID_QuestionType") = 11 Then ShowQuestion = ShowQuestionType11(ID_Question, ...)
If objDataReader("ID_QuestionType") = 12 Then ShowQuestion = ShowQuestionType12(ID_Question, ...)
If objDataReader("ID_QuestionType") = 13 Then ShowQuestion = ShowQuestionType13(ID_Question, ...)
If objDataReader("ID_QuestionType") = 14 Then ShowQuestion = ShowQuestionType14(ID_Question, ...)
If objDataReader("ID_QuestionType") = 15 Then ShowQuestion = ShowQuestionType8(ID_Question, ...)
If objDataReader("ID_QuestionType") = 101 Then ShowQuestion = ShowQuestionType101(ID_Question, ...)
If objDataReader("ID_QuestionType") = 102 Then ShowQuestion = ShowQuestionType102(ID_Question, ...)

This makes me dry heave! Maybe a little GoF Strategy pattern? What happens when Question type id 103 emerges? Dare I say that the class I found this piece of code in consists of 2826 rows!!

I don't know what I want with this post, probably nothing just had to get it of my chest.


Feedback

No comments posted yet.


Post a comment





 

Please add 6 and 4 and type the answer here:

 

 

Copyright © Niklas Nihlen