LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-18-2005, 08:57 AM   #1
eantoranz
Senior Member
 
Registered: Apr 2003
Location: Costa Rica
Distribution: Kubuntu, Debian, Knoppix
Posts: 2,092
Blog Entries: 1

Rep: Reputation: 90
I think there is a problem with Java (extending interfaces)


This is the short explanation:
I have two interfaces. They define the same methods, with only one difference between them, one of them throws Exceptions, and the other doesn't (You might be guessing I'm working with EJBs, right?). If I "mix" them together in a single Interface that implements both of them, It turns out that the methods will throw the Exception. But I think that doesn't make that much sense, because one method that doesn't throw a exception can overide one method that does throw exceptions, but it's not possible to do otherwise. Then why does it throw the exception?

Description of THIS particular problem
I (personal taste) like to make one interface that is then extended by the local and the remote interfaces.

I extend that interface in a new interface that is the remote one. I extend the same interface in a local interface and override all the methods so that they don't throw any exception (quite a pain in the ass, right? I'm stubburn, what can I say?).

I have decided to make a base class that will be extended by a number of EJBs. This base class defines a number of methods. I have declared the methods in one interface (not local, not remote, remember, It's a business logic interface) that throws RemoteExceptions. Then, when I want to create the actual Bean that will extend the base EJB (that doesn't work at all) I have to make the business interface. No problem. I extend the base business interface andd add the business methods. I then create the remote interface extending the extended business interface and implementing EJBObject. Now is the time of the Local Interface. I would have to extend My business Interface and implemente EJBLocalObject.... AND overide every freaken method (base and extended) so that they don't throw RemoteExceptions. I can't avoid having to overide the methods not defined in the base interface.... but I think It makes sence to create one local interface that overrides the base methods and then extend this interface so that I don't have to redeclare all the methods so they don't throw RemoteExceptions. Are you with me?

Maybe with code I'll be a little clearer:

Base Business interface:
Code:
public interface BaseInterface {
	public void baseMethod() throws RemoteException();
}
Abstract bean Implementation (remember.... this won't be "published"):
Code:
public class BaseBean implements SessionBean, BaseInterface {
	// all the methods that you know a bean has to have....
	public void ejbCreate() {}
	blah blah

	// and then
	public void baseMethod() {
		System.out.println("BaseMethod");
	}
}
Now... the extended business interface:
Code:
public interface ExtendedInterface {
	public void extendedMethod() throws RemoteException();
}
Remote Interface:
Code:
public interface Extended implements ExtendedInterface, EJBObject {
}
Now is when it get's tricky. Local Interface. If I'm going to have to override 50 times the business method of the base interface, I think it makes sense to override it once so that It doesn't thow RemoteException:
Code:
public interface BaseLocal extends BaseInterface, EJBLocalObject {
	public void baseMethod();
}
and then this is my "theory". It SHOULD be possible to make this:
Code:
public interface ExtendedLocal extends ExtendedInterface, BaseLocal, EJBLocalObject {
	public void extendedMethod();
}
This is my thinking: Both ExtendedInterface and BaseLocal have a baseMethod() definition.... BaseLocal doesn't throw RemoteException, but ExtendedInterface does. I think that in order to "fit" in both interfaces, the result SHOULDN'T throw RemoteException, because then It wouldn't fit in the definition of BaseLocal (checked exceptions not thrown in a method can't be thrown by overriding methods). Am I missthinking? Quite a piece of writing, right?

Last edited by eantoranz; 03-18-2005 at 08:59 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with the interfaces... Tomanas Slackware 1 10-09-2005 12:38 PM
Extending partitions bender103 Linux - Software 2 03-09-2005 06:00 AM
Extending /tmp Walter Sobchek Linux - Software 3 08-11-2004 05:05 PM
Is there a Linux app to help layout user interfaces for Java? BobBuchanan Programming 1 06-01-2004 08:23 PM
Java - Interfaces, inner classes and callbacks for events gwp Programming 3 12-09-2003 04:25 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:31 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration