When is it desired to have reflection based instantiation instead of a normal instantiation via a new? Is it a good software engineering practice?
When is it desired to have reflection based instantiation instead of a normal instantiation
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Using reflection is required when your program does not have a compile-time access to the class, for example, when the class is provided in a library at run-time, and the name of the class and the path to the library are provided to your program as part of configuration. Independently developed plug-ins for your program are good candidates for reflection-based instantiation. Reflection-based instantiation may be desirable in other cases as well: for example, when you know which classes you want, but you do not know ahead of time in what way you want them to be connected. Constructing expression trees is an example of this situation.