Alex Rivera | Logout

Is using reflection a design smell?

Asked 2009-07-30T05:04:34.383
36

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.

Edit
Report

1 Answer

1

I'm in the middle of a project that uses (for my first time, ever) Reflection. I have to admit, it doesn't look very good. Normally I strive for very minimal commenting, in the belief that code should be self-commenting to the max extent possible, but with this project I am adding frequent comments; this is both to explain what's going on to the next developer who may have to maintain the code, and as "thinking out loud" for my own benefit.

Bottom line: if it doesn't look obvious, add comments. Always think about the person who comes after you who may have to deal with your mess. Reflection can look messy, so comment accordingly.

answered 2010-08-21T16:57:09.207

Your Answer