Women in Technology

Hear us Roar



Article:
  Understanding Reflection, Part 1
Subject:   Yes, but Why?
Date:   2004-07-14 09:49:59
From:   andcal
Response to: Yes, but Why?

There may be instances where you need to run several methods from the same assembly. For instance, when a user changes his/her password, th3e proposed new password would need to be checked against each one of the company's password rules.
You could have the password change application use reflection to dynamically find all methods of the business rule assembly which contains the password rules (Each password rule is represented by one method). Then the change password app can call each of those methods, passing the (password) string, and checking for a return of boolean true.
If you ever need to add a new password rule, you would only need to modify the password rule assembly, adding the appropriate business rule method. The calling application would still dynamically find each method, including the new one you added, and run each of them.
Since you are changing less of the code, this can reduce the amount of testing needed before deploying the updated version.