Suppose I make a class called "Government." The government has members such as officers, ministers, departments, etc. For each of these members I create an interface, and any particular government defines them as it sees fit.
The main method in the government class is called Serve(Request req) . Suppose the request speed is very high (1000+ requests per second).
To create a government, I can:
1) Use Java generics to write Government<Class Minister, Class Officer, ...> , and any specific government implementation should create its own government object in Java code, and main() - an expanded bank.
2) Have a configuration file that indicates the names of the classes of officers, ministers, etc., and whenever Serve() is called, it uses Class.forName() and Class.newInstance() to create a class object. Any new government just needs to write classes for its members and a configuration file. For all governments, there is one main() .
From a purely official point of view - which is better and why? My main concerns:
a) does forName() do an expensive search every time? Suppose there is a very large universe of classes.
b) Will we skip compiler optimization that can be done in case 1, but not in case 2 in dynamic classes?
source share