Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

B&S: server-client communication

 
hatim osman
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there
It's been a while, I am stuck in this problem for almost a week now and hope you guys can help me out. I am implementing a socket based solution, and in a previous thread, some fellows suggested me a brilliant idea regarding server-client communication thru the use of command Pattern. Everything went fine until I was struck by this!? Let me explian the problem clearly so you can get better understanding of what I am up against. It won't take long time..promise
My client controllers don't care whether it's serving a local or remote client:

All the load lies on the ContractorServices argument which is in fact an interface that describe the services contract:

public interface ContractorServices {
public void book(int recNo, String id) throws AlreadyBookedException,
ContractorNotFoundException,IllegalAccessException,
ContractorServicesException;
//more services methods

I also have default implementation of this interface:

Things looked good, until I finished coding my RemoteContractorServices class. This class open a socket connection to the server, hence it has the potential of throwing IOException(s) of it's own, which are far from being related to the business logic, I considered coding remote GUI controllers that are simply duplicates of the local controllers but have the capability of cathcing IOException. However, I thought this will increase the number of unnecessary classes and may violates these must requirements as well:
Architecturally, this mode must use the database and GUI from the networked form, but must not use the network server code at all

and
Your user interface should be designed with the expectation of future functionality enhancements, and it should establish a framework that will support this with minimal disruption to the users when this occurs

That's why I chose to keep my controllers intact:

Currently, I dealt with this problem. but I am not sure if represents good OOP and good exception handling strategy:


Please help me out, I can't go further and worsen the situation

Thanx in advance
Hatim
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 12007
215
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Hatim,

From what I can see, your ContractorServicesException is thrown for any problems accessing the data in stand-alone mode. As such, having the ContractorServicesException thrown for any problems accessing the data in networked mode makes sense as well.

Off topic: one thing I would recommend though, is changing your exceptions such that they used chained exceptions. An article on this is here. Using this, your code would change from:To:All the (minimal) work will be in having a second constructor for your Exception, however once you have done this it means that your stack trace will be much more valuable if ever anyone needs to debug your code.

Regards, Andrew
 
hatim osman
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
Thanx alot, that helped alot, honestly I was going quite far with this, I was considering the use of a RuntimeException. But your remarks make more sense.

Hatim
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic