Maybe this question is more about java, but probably somebody knows the answer...
I have an application which is intended to process some data. The data processing is done by executing a list of commands(program or script), stored in an ArrayList. The script may be loaded from a file and be something like this: GET (ITEM 1234) SET (33) and so on... nevermind.
All commands extend the basic class Command and look like this:
- GetItem extends Command
- {
- String scriptName = "CREATE";
- int argNum = 1;
- Data data;
- int itemNumber;
- ....
- GetItem(Data data_, itemNumber_)
- {
- data = data_;
- itemNumber = itemNumber_;
- }
- int execute()
- {
- return data.get(itemNumber_);
- }
- }
The question is this: can I let the application to load some custom classes describing commands? That is, can I make the list of available commands easily extensible? Say, all command are listed in some text file:
CREATE : CommandCreate.pde
Currently the application may only support the set of commands that were fused into it during creation. So is there any way to make it support adding custom commands as class files? Maybe some sort of try-catch would work?
1