Skip to main content
Tweeted twitter.com/StackSoftEng/status/1040118221599383552
edited title
Link
Kilian Foth
  • 111k
  • 45
  • 301
  • 323

Alternate of Reflections Alternative to Reflection

Source Link

Alternate of Reflections

I will directly come to our current working flow so that you can understand the problem in a clear picture.

I am attached in Laboratory Automation System in which Analyzer (a machine that performs medical tests) sends data to Host (our Automation System). Every analyzer is assigned a unique ID (Machine ID) and is saved in Database with its relevant controller's complete path. A controller is simple Java class that keeps the connection between Analyzer and Host.

Now that controller (a java class) is instantiated at run-time when user turns on our software. User provides machine id and based on that machine id, its relevant controller is instantiated. The Controller is instantiated using Reflections which is the PROBLEM here. We are looking for a solution to avoid using Reflection.

Adding to the complexity, we have multiple Analyzers of same types, which means we will have same Controller for every Analyzer of same type. In other words, If we have 5 same Analyzers, our program will use Reflections to create its instance.

I hope I made my point clear, What approach is best alternate of Reflections? Please note that I know Design Patterns and all stuff but probably none of that solved my problem and we are still relying on Reflections.

Thanks, let me know if further information is required.