0

I have 10 different types of report which I want can generate.

Reports have id like 501,502,503...

Different report is generated by separate function, so instead of writing

if(reportId == 501){
 generate report 501
}
if(reportId == 502){
 generate report 502
}...

I thought about creating a dictionary where I bind int to a delegate. But it is a bad practise which is outlined in comments of the answer of the following question : Question

What do I do in my situation, where I get an integer and I have to find out which function to call?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Timsen
  • 4,066
  • 10
  • 59
  • 117

1 Answers1

1

It isn't a bad practice - it depends on your design, if you only have atomic functions its fine, if you have associated data or context with the functions, you would need to go for classes and apply something similar to Strategy / Command / Chain of Responsibility patterns.

krafty
  • 425
  • 4
  • 16