• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Design feedback

 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everyone
After much chopping and changing I have decided on the following design for my data client: any comments very welcome, please feel free to criticize, my ego can take it
I have two interfaces


Now the Data class implements DataInterface and my RemoteData class implements RemoteDataInterface. I am using RMI and my RemoteData instance itself contains a Data instance.
On the client side I have a factory that churns out DataInterface type objects for use by the client. In the case of a local connection the factory returns a Data object and for a remote connection it gets a RemoteData instance from the server then wraps it in a class called RemoteDataAdapter which also implements DataInterface and returns that to the client app.
The RemoteDataAdapter class catches all the RemoteExceptions, IOExceptions actually (I use IOException in the interface so that my application is not tied to RMI but could use sockets or any other transport mechanism.) but throw RemoteException in the implementing RemoteData class. My RemoteDataAdapter then converts my IOExceptions to DatabaseExceptions to comply with DataInterface.
Finally but DataInterface instance is passed by the connection factory to a class called DataAccess that performs the tasks of book, search etc. on behalf of the client.
I know alot of others have had two interfaces but had both DataInterface and RemoteDataInterface throwing RemoteException, or IOException, as the remote interface extended the local one but I really didn't like this as I would then be throwing and catching exceptions in local mode that would never actually be thrown and caught and thought this would be confusing for the reader. Now everything ultimately just throws DatabaseException.
This also means I am free to vary my implementation for the remote connection without breaking the interface used by DataAccess. In other words I am free to change the implementation of RemoteDataAdapter to use any reference I like and catch whatever I want so long as it conforms to DataInterface.
Feel free to blow it out of the water if you wish.
Have a good weekend all
Many thanks
Sam
 
If I'd had more time, I would have written a shorter letter. -T.S. Eliot such a short, tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic