Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding implementation without recompiling in Java?

Hey everyone, I'm a college senior with my first real job opportunity (exciting). I'm at the stage now where they need to see a programming example, and they gave me the task of implementing a random number generator service in Java, with two different implementations (one using the built-in stuff and another of my choice). The code is the easy part, but one part of the task is confusing me... here it is:

As the evaluator, I should be able to do the following: Compile my own project with the candidates jar file. Register my solution with the candidates executable jar. Run the candidates executable jar, somehow telling it to run my implementation.

Basically I'm making my code into an executable .jar, and

evaluators should be able to use the code and compiled classes developed by the candidate to plug in their own random number generator implementation without recompiling the candidate’s code.

What the heck does that mean? Maybe I'm just missing something obvious? I'm not sure how to allow them to just throw in their own implementation without having to recompile everything... hopefully it's not too big of a task, as I haven't heard of something like that (I think) at my University.

Any help/insight is really appreciated!

like image 538
Eric Jackson Avatar asked Dec 06 '22 03:12

Eric Jackson


2 Answers

I think it just means that you should provide a RandomNumberGenerationStrategy interface as part of your public API, that the evaluator can implement.

Then provide another hook whereby he can register his particular implementation of your interface, which you then invoke via callback.

like image 179
Kevin Pauli Avatar answered Dec 07 '22 15:12

Kevin Pauli


They want you to load the implementation JAR with an URLClassLoader (see the docs) and then use reflection to instantiate the main class and call the correct method to invoke the random number generator.

like image 30
Aaron Digulla Avatar answered Dec 07 '22 17:12

Aaron Digulla