Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is using reflection a design smell? [closed]

I see a lot of C#, .net questions solved here using reflection. To me, a lot of them look like bending the rules at the cost of good design (OOP). Many of the solutions look unmaintenable and "scripty".

Is using reflection a good practice in general? Are there things that can only be solved by reflection?

edit:

Please give examples where reflection is the only good solution.

like image 697
Mank Avatar asked Jul 30 '09 05:07

Mank


1 Answers

Examples:

  • Dynamic loading of types via configuration
  • Using "convention" style registration (register components with your container that implement an interface or have a certain naming convention)
  • Checking for/using custom attributes/type metadata

Reflection is a tool, like "throw". should you use throw everywhere? No! So is it a code smell to use throw?

like image 153
Philip Rieck Avatar answered Sep 21 '22 08:09

Philip Rieck