I'm doing the urlybird project for the developer exam. I am told to use a DBAccess interface (declares the database methods I needs to implement) and that I can't change it. I have a class that implements this interface called Data.
I want to use RMI in my solution. To use RMI, I need an inerface that extends Remote. How can I use the DBAccess interface to do this if I can't change it?
Help???
peter wooster
Ranch Hand
Joined: Jun 13, 2004
Posts: 1033
posted
0
Originally posted by berry westover: I'm doing the urlybird project for the developer exam. I am told to use a DBAccess interface (declares the database methods I needs to implement) and that I can't change it. I have a class that implements this interface called Data.
I want to use RMI in my solution. To use RMI, I need an inerface that extends Remote. How can I use the DBAccess interface to do this if I can't change it?
"How can I use the DBAccess interface to do this if I can't change it?"
The Remote interface is a "marker" interface; that is, Remote defines no members. The purpose of the Remote interface is to indicate that an extending interface uses remote methods.
peter wooster
Ranch Hand
Joined: Jun 13, 2004
Posts: 1033
posted
0
Originally posted by J Borderi: "How can I use the DBAccess interface to do this if I can't change it?"
The Remote interface is a "marker" interface; that is, Remote defines no members. The purpose of the Remote interface is to indicate that an extending interface uses remote methods.
It's not quite that simple, from the API reference for RemoteException:
A RemoteException is the common superclass for a number of communication-related exceptions that may occur during the execution of a remote method call. Each method of a remote interface, an interface that extends java.rmi.Remote, must list RemoteException in its throws clause.
So if you just implement Remote, you will need to add a "throws RemoteException" to all your methods. That breaks the rule about not modifying the DBAccess interface. Look at the Adapter pattern for the way out of this bind. See my other posts for details.
Paula Decker
Ranch Hand
Joined: Dec 17, 2004
Posts: 36
posted
0
Hello,
I have an interface question along this line. I want to throw a DatabaseException, but this exception is not listed in the DBAccess interface. Should I add the DatabaseException to the DBAccess interface? I thought we were not supposed to modify it. Thanks very much.
-Paula
Paula Decker
Ranch Hand
Joined: Dec 17, 2004
Posts: 36
posted
0
Can someone answer this question, please:
Does the assignment allow a DatabaseException to be exposed to the client? Can it be added to the DBAccess interface, or should it be in a different interface.
Thanks!
-Paula
Andrew Monkhouse
author and jackaroo
Marshal Commander
I would strongly recommend against changing the provided interface. It represents a contract between you and any other programs that wish to use your Data class. If you add an exception to the interface, then any other programs which have already been written to that interface will instantly be broken.
In the very real case of this assignment, you have been told that some parts of the assignment will be tested using automatic testing software. The most logical way for this to happen is if they test your Data class, which would mean that changing the interface will stop the automatic testing software from working - automatic failure .
At a higher level (say at your networked server level) you could always expose more exceptions if you like.
Thanks for the direction. I now plan on throwing a DatabaseException which is a subclass of RuntimeException. This will not change the signature of the required interface.