aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes NX:about interface design Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "NX:about interface design" Watch "NX:about interface design" New topic
Author

NX:about interface design

Nai chao Wu
Greenhorn

Joined: Apr 02, 2004
Posts: 4
hello everyone
My English is poor,I hope that everybody can understand me.
sun provides a interface DBMain :
public interface DBMain {
// Reads a record from the file. Returns an array where each
// element is a record value.
public String [] read(int recNo) throws RecordNotFoundException;
// Modifies the fields of a record. The new value for field n
// appears in data[n].
public void update(int recNo, String [] data)
throws RecordNotFoundException;
.
.
.
These methods only throws a Exception-RecordNotFoundException
I want to design a remoteInterface which extends DBMain and Remote
These methods in the remoteInterface must throw RemoteException.
If these method throw RemoteException,program won't compile successful.
Because method in the DBMain don't throw RemoteException or its parent.
Can interface DBMain be modify to throw IOException?
who have a good solution?
Thanks
Paul Tongyoo
Ranch Hand

Joined: Sep 30, 2003
Posts: 91
Originally posted by Nai chao Wu:

Can interface DBMain be modify to throw IOException?
who have a good solution?

Hi Nai--
Forgive me if my advice is incorrect -- it's been awhile since i've posted after I passed the SCJD exam, I needed a break!
You can definitely extend the DBMain interface to adhere to the one you want. Just make sure you don't change the actual DBMain interface itself.

However, there is an alternate approach you may want to consider: rather than extending the class and inheriting all of its functions, have you considered using some sort of object delegation approach?

In both cases I'm adding to the functionality of DBMain, but make sure I don't change the DBMain interface itself.
HTH
Paul
[ April 03, 2004: Message edited by: Paul Tongyoo ]

Sun Certified Java Web Component Developer for J2EE v1.4<br />Sun Certified Java Developer for J2SE v1.4<br />Sun Certified Java Programmer for J2SE v1.4
Nai chao Wu
Greenhorn

Joined: Apr 02, 2004
Posts: 4
Thanks Paul
My meaning is The exceptions thrown by a subclass'method may be equal to or fewer than those thrown in the superclass'method.The overridden method must explicity declare which methods it can throw.
For example
public interface DBMain{
public String [] read(int recNo) throws RecordNotFoundException;
}
import java.rmi.RemoteException;
import java.rmi.Remote;
public interface RemoteInf extends DBMain ,Remote
{
public String [] read(int recNo) throws RecordNotFoundException,RemoteException;
}
compile:read(int) in RemoteInf clashes with read(int) in DBMain;
overridden method does not throw java.rmi.RemoteException
If method in DBMain throw RemoteException or IOException,it will compile successful.
but DBMain isn't modified.

Nai
 
Don't get me started about those stupid light bulbs.
 
subject: NX:about interface design