The Most Efficent Way To Organize A Lot Of Methods
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 TO NEED TO EXTEND A CLASS THAT DEALS WITH HOW TO INTERRUPT
DATA.What is the most efficient way 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?
I could put them into different classes and make the methods static. It is
very similar to the previous one
I could leave it like it 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,
so I would really not want to waste memory.
No comments:
Post a Comment