*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Have an interfcae question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Have an interfcae question" Watch "Have an interfcae question" New topic
Author

Have an interfcae question

berry westover
Greenhorn

Joined: Dec 24, 2004
Posts: 5
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
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?

Help???


You need to use the Adapter pattern, see my post in Local Adapter Question for details on how to do this.
Joe Borderi
Ranch Hand

Joined: Oct 23, 2004
Posts: 151
"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
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
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
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

Joined: Mar 28, 2003
Posts: 11405
    
  81

Hi Paula,

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.

Regards, Andrew


The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Paula Decker
Ranch Hand

Joined: Dec 17, 2004
Posts: 36
Hi Andrew,

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.

-Paula
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Have an interfcae question
 
Similar Threads
URLyBird's [Version 1.2.3] and network side
how do I return a DBAccess interface back to client?
DBAccess interface
Why DBAccess is not a valid Remote interface?
altering DBAccess interface