I am making a mock-java langue, which has a lot of methods. I would group similar methods together and put them in their own class, but all of the methods need to extend a class that deals with how to interrupt data. What is the most efficient way, in terms of runtime performance, to organize them?
Right now it is just a bunch of methods in one class (ListOfMethods
) called with a special method with if-else statements to find the right method, like:
public void methods(String name, String param) throws NumberFormatException, InterruptedException {
if (name.equals("systemexit")) SystemExit(param);
else if (name.equals("sleep")) sleep(param);
}
public void SystemExit(String param)
{
int exit=(int)Double.parseDouble(param);
System.exit(exit);
}
public void sleep(String param) throws NumberFormatException, InterruptedException
{
Thread.sleep((long)Double.parseDouble(param));
}
I am not trying to change this format, just how the methods are organized. I want to group them into classes, like math and strings, but I am wondering the best way to do this?
ListOfMethods
could extend each class. The problem is that Java does not support multiple inheritance, so class 1 would extend class 2 which would extend class 4, etc.ListOfMethods
could import each class. The problem with this is that they all need to extend a super class. Is that inefficient?- Placing them into different classes and making the methods static (very similar to the previous one).
- Simply leaving it as is.
I am open to other suggestions - I want to make it as efficient as possible. Thanks in advance.
Note: there will be hundreds of instances of this class running at once - this is just a short example of the actual problem - so I would really not want to waste memory.