//DYNAMIC BINDING I am writing a JAVA(SWING/GUI) program that recognises certain commands.Users will enter command and the program executes the command.I want to be able to add commands in future.I have been able to do it with IF/ELSE statements and would like to do it using polymorhism so as to allow dynamic binding.Part of the code is shown below
Somebody suggested the following but I don?t quite understand: 1. Build a class with the following methods: String[] getFunctions (); Object[] getFunctionParams (String function); boolean accept(String functioncall,String[] args); boolean execute (String funcall, String[] args); 2. You could then just recompile your class with updates that would be recognizable to your console under this framework, or you could do something like this. public static void main (String[] args) { MyProjectOperations = class.forName(args[0]).instanceOf(); } I would appreciate if someome can tell me how to acchieve this. . .
It really depends the way you want to tackle the problem... Give a look at the http://www.javacoder.net/patterns.jsp I would consider many of the patterns if I were you : _ PROTOTYPE _ BUILDER _ FLYWEIGHT You have of course the COMMAND which should really serve your purpose ...