Let's say I have a package that contains all subclasses of 'Device', like this one:
class TV extends Device{
@override
public void run() {
//code goes here
}
private void moreMethods(String args){
// more code
}
}
In the main class it should be possible to instantiate and run every subclass of Device at runtime by calling everyone's 'run' method.
The benefit of this is to allow users to simply put new Device files into the package and said files will run automatically without having to edit the main class.
Is there a clean way to do this? I was thinking that maybe if I had a txt file in that package with every subclass name, it would be possible. Minor inconvenience being the user had to edit the file and add the new device's name.
Is there another way to achieve the same result? I'm interested in providing a way for users to add new device files without editing existent code.
Aucun commentaire:
Enregistrer un commentaire