mardi 27 octobre 2015

Command Pattern basics

Suppose I have a file with contents like this, which is a combination of some config information and some commands:

server1 192.168.0.1  
server2 192.168.0.12  
file1 /home/user1/file1  
upload file1 to server1  
ping server1  
replicate server1
shutdown server1  

The command pattern is well-suited to this as each of "upload", "ping", "replicate", and "shutdown" can be represented as a command.

However, I still have a few questions:

1. Whose responsibility is it to parse the input?
The input file has necessary information like where the files and servers are. Who will do the parsing? Client? Receiver? Invoker?

2. Where should the parsed information be stored?
The parsed information from first 3 lines would go in a HashMap. According to DZone's blog post,

The Receiver has the knowledge of what to do to carry out the request.

So, I am guessing Receiver is the one where the HashMap will stored?

3. Can commands return results?
Commands like "ping" or "shutdown" should indicate what happened after the command was executed. Can these commands return values?

Aucun commentaire:

Enregistrer un commentaire