Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Have an interfcae question

 
berry westover
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1033
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 151
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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
Posts: 1033
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 11854
185
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Paula Decker
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic