I am working on a program, which is supposed to have "Modules" which people can make their own code from an API, and they can then add one of their Modules
, let's say it's called ModuleNicerText
, they add it to the MyProgram\Modules
folder as a .java class (the source), and the class implements Module
.
The Module
class has one method (well, it has more but for the sake of this post I'll say one), called onUpdate()
, and I want to be able to somehow import that class to my code, and then run the .onUpdate()
whenever I need to, I hope I explained it well enough, if I haven't then here is another example:
I have an interface, named Module
this is the body of Module
:
public interface Module {
void onUpdate();
}
Now, I have my main class named MyProgram
, and in that class I have this method:
public void onUpdate(){
for (Module module : modules){
module.onUpdate();
}
}
I use this kind of system, so I can easily add or remove components without having to mess with a bunch of stuff, if it is all crowded in one class/method.
Now, there is a directory that gets created when the program is run which is MyProgram\Modules
and anyone who wants can add a .java file which extends the Module
interface there.
I want to be able to look through the .java files in that directory and be able to call the .onUpdate()
method for them, so that my users can have as much customization as they possibly can!
Any help at all is very much appreciated, and I thank you in advance for taking your time to read this enormous wall of text :)