I'm writing a red5 application in Java. it just means that I have a bean that points to my main class app class that's called Application.
I have several classes that I want to add and remove like modules to my application.
example:
I have two classes called 'A' and 'B', each one of them contains the public function testme(). I want somehow to configure that my main Application class will call the constructor of these two classes and that somehow my main Application class will contains the functions Atestme() and Btestme() that will call the appropriate testme() function in the appropriate class. is there a way to achieve such a thing without me manually creating these functions and calling the appropriate function within one of the classes?
Is there a way to use bean configuration to achieve such a goal ? (I want to be able to configure adding and removing 'modules' using bean configuration if possible)
I started reading about reflections, and it says that adds performance overhead and I should avoid for production environments that are time and cpu sensitive.
is there a way to catch when aDoTest() or bDoTest() is called in my main class and to catch it in order to call the appropriate functions ?
How about this:
public class Application {
public static void aDoTest() {
doTest(new A());
}
public static void bDoTest() {
doTest(new B());
}
private static doTest(Testable t) {
t.testMe();
}
public static void main(String[] args) {
aDoTest();
bDoTest();
}
}
public interface Testable {
public void testMe();
}
public class A implements Testable {
public void testMe() {
// ...
}
}
If this does not help, you need to clarify your question.
Perhaps you are wanting to catch calls to non-existent (i.e. undeclared or unimplemented) methods and turn them into calls to real methods. If so, you can give up on that idea. Java won't let you do it.
The closest that you can come is to generate a new class at runtime with implementations for this methods:
Proxy
class to create a dynamic proxy implementation of some interface.But these approaches are all complicated and expensive. (Probably a lot more expensive that using reflection, unless the generation cost can be amortized over a huge number of calls.)