Implementation of a Protocol for Server/Client communication

I am trying to program a Server/Client application in which I have to implement a protocol for them to communicate. The server is supposed to load an address book from a file, and then allow the client to add/delete from it.  I have the server and client classes and I created a protocol class that recognizes the messages from the client, but I am a little confused on the correct way to do the add/delete to the file.  The way that I am structuring it is that the client sends a command to the server, the server then passes this message to a method in the protocol class.  The server also loads the file when it starts.  So is the correct process then to just return a value from the protocol indicating the type of command for the server to do on the file, and then proceed from there?  I don;t think the protocol class should write to the file, but I am a little confused on which class should write to the file.  Thank you!
Who is Participating?
nayernaguibConnect With a Mentor Commented:
I would delegate the I/O work to a "persistence manager" class implementing a generic I/O interface. This makes it easier to modify the persistence method without changing server/protocol code. For example, you might later decide to store the address book in a database rather than a file. In this case you will only need to create and instantiate a new class implementing the generic I/O interface, and use it in place of the filesystem I/O class. You can instantiate your I/O classes by creating a factory class that will return an instance of a persistence manager of a specific type that is provided as a parameter to the Factory.getInstance() method.


  Nayer Naguib
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.