This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

DataAccess class for remote/local

 
Renato Mascardo
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is a quick question in regards to the Data classes. My design has the following:
1) Data Class --> Provided by Sun
2) DataAccess Interface implements Remote --> Includes all the method signatures of the Data class
3) DataAccessLocal implements DataAccess
4) DataAccessRemote extends UnicastRemoteObject implements DataAccess, Unreferenced
The question I have is that my DataAccess class implements Remote even though I don't really use it for the DataAccessLocal. I don't see any problems with that design but is there a better way to do that? Should I add another interface that extends DataAccess and implements Remote?
Thanks!
-Renato Mascardo
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Either way will be fine. I had the same design and it worked fine. Like you said have Remote extended in the interface is fine and won't hurt in local mode.
Mark
 
Renato Mascardo
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Mark. The only weird thing is that in my DataAccessFacade, I need to wrap the DataAccess calls in RemoteException try-catch even though its running in local mode. I'm assuming that your code does the same thing and it seems not necessary in Local mode.
What do you think?
-rjm
 
Jason Moors
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Renato,
I've been struggling with the same dilemma, I think I�ve come to the conclusion that the DataAccess interface should be a generic interface, and hide the actual implementation from the DataAccessFacade. My decision for this has been based upon the JDBC interface, it provides a generic interface �Connection� which hides the actual implementation (data access).
The issue I still undecided upon is whether the interface should throw a generic exception like Exception or IOException. Mark has suggested in previous posts that all the methods could be defined to throw Exception, I like the idea as it would enable future implementations to throw other exceptions than just RemoteException, DatabaseException etc, my only concern is that I don�t think it is a good idea to catch Exception as it tends to be a bucket, and the javadocs will not provide the developer with much information.
Jason.
 
Richard Jackson
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the above statement,there is a state:
2) DataAccess Interface implements Remote --> Includes all the method signatures of the Data class

Who can explain that from 2 points?
1.May a interface implement another interface?
2.Includes all the method signatures of the Data class This mean that all the methods containing into the Data class can be moved to the new class?
Wait for your reply.
Regards,
Richard
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 11914
209
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Richard,
May a interface implement another interface?

Probably a typo. An interface cannot implement anything. It can, however, extend other interfaces.
Includes all the method signatures of the Data class This mean that all the methods containing into the Data class can be moved to the new class?

No, Data still has the methods it requires. However Renato has created an interface which almost matches perfectly the methods in Data.
I would ignore this if I were you. Renato is doing the Fly By Night Services assignment, which has some requirements that you do not have.
Regards, Andrew
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic