A simple Command Interpreter

R

Ramkumar Menon

Hi,

I have a scenario where a client pgm passes a command string to a
Command Interpreter. There are several possible commands. The Command
Interpreter accepts these command strings and makes API invocations on
some other object.
Some Commands would need to return a value, whereas some others do not
need to. These results need to be passed back to the client.

For isntance, one command could be somethinfg like
<getAllCustomers/>.Another command could be like <deleteCustomer
name="foo"/>. The former would return a Document of all Customers. The
second one does not return a value,but could throw an Exception.
I was thinking of a CommandInterface with a single method named
processCommands(String commandXML(. But this would not work if I need
to have different types od return values. Moreover, these APIs are more
or less unrelated to each other. i.e. different from a Strategy pattern
where there is a specific heirarchy/relationship.
My questions are:
1) What should the Command Interpreter interface look like ?
2) What is the best way to dispatch the XML requests to different API
invocations on a particulat object. For instance, <getAllCustomers/>
should invoke CustomerManager.getAllCustomers(). <deleteCustomer
name="foo" should invoke CustomerManager.deleteCustomer("foo"); Note
that there is more than one class on which the APIs could be invoked.
For instance, there could be an AccountsManager class on whom Account
related queries would be dispatched to.

Any ideas are welcome.

rgds.
Menon.
 
R

Roedy Green

Some Commands would need to return a value, whereas some others do not
need to. These results need to be passed back to the client.

What's wrong with calling methods in classes? It sounds as if your
requirements are too general for command.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,049
Latest member
Allen00Reed

Latest Threads

Top