1

So I'm building a fairly simple file transfer server/client but having a hard time to figure out a good design for processing different commands and states within the protocol..

Say that you have 3 different commands upload, remove, download, you could use 3 different if-statements and keep track of states with additional if-statements, but that wont scale and will be impossible to maintain..

The Chain Of Responsibility design pattern could be used for sequential stuff such as encryption and compression, but it wont take care of the logic for commands.

I know that this is a quite broad question, but does anyone have any suggestions?

  • You can always use a `Map` where keys are command names and values are implementations of an interface for executing these commands. That is one solution amongst many – fge Feb 15 '14 at 17:43

1 Answers1

1

The following may be helpful:

To provide different implementations for the same operation based on some conditions: http://en.wikipedia.org/wiki/Strategy_pattern

To maintain state of the communication (e.g. the current protocol command): http://en.wikipedia.org/wiki/State_pattern

For security/compression: http://en.wikipedia.org/wiki/Decorator_pattern or Chain-of-responsibility

Vitaly
  • 2,760
  • 2
  • 19
  • 26