java - Command Pattern basics -
suppose have file contents this, combination of config information , commands:
server1 192.168.0.1 server2 192.168.0.12 file1 /home/user1/file1 upload file1 server1 ping server1 replicate server1 shutdown server1
the command pattern well-suited each of "upload", "ping", "replicate", , "shutdown" can represented command.
however, still have few questions:
1. responsibility parse input?
input file has necessary information files , servers are. parsing? client? receiver? invoker?
2. should parsed information stored?
parsed information first 3 lines go in hashmap
. according dzone's blog post,
the receiver has knowledge of carry out request.
so, guessing receiver 1 hashmap
stored?
3. can commands return results?
commands "ping" or "shutdown" should indicate happened after command executed. can these commands return values?
- whose responsibility parse input?
each line has 2 parts: command name, , arguments. arguments command-specific, should have commandsprovider
should:
- split file lines
- for each line separate first word , other words
- create command according first word (you may have
commandsregistry
knows how find command name) - provide arguments command
command pingcommand
knows first argument server. in theory, may pair each command argumentsparser
takes array of words , configures command it, not sure necessary.
- where should parsed information stored?
information stored in command, receiver executes it.
- can commands return results?
yes, can implement execute()
method like.
Comments
Post a Comment