• 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
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

Have an interfcae question

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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???
 
Ranch Hand
Posts: 1033
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author and jackaroo
Posts: 12199
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
I want my playground back. Here, I'll give you this tiny ad for it:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic