Re: Interface design problem
This message is in MIME format. The first part should be readable text,
while the remaining parts are likely unreadable without MIME-aware tools.
---910079544-1933340422-1219740363=:30818
Content-Type: TEXT/PLAIN; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 8BIT
On Tue, 25 Aug 2008, Stefan Ram wrote:
Royan <romayankin@gmail.com> writes:
public interface IFileSystem {
public char[] readFile() throws IOException;
public interface INetwork {
public char[] readFile() throws IOException, RemoteException;
interface System< E extends java.lang.Throwable >
{ public char[] readFile() throws java.io.IOException, E; }
interface FileSystem extends System< java.lang.RuntimeException >{}
interface NetworkSystem extends System< java.rmi.RemoteException >{}
That doesn't really help, because you have to throw away polymorphism to
do it. If you write a program around FileSystem or System<IOException>,
you won't be able to substitute NetworkSystem in its place. You'd have to
genericise your client code, and write it all in terms of System<E>, which
would be a headache.
I'd take the approach of forcing the remote exceptions through the same
exception types as other exceptions. If the RemoteException is the one
from java.rmi, that's trivial, because it's already a subclass of
IOException. If it's a user-defined exception, i'd make it a subclass of
IOException. If you're feeling like overcomplicating things, you could
define a new FileSystemException, and have subclasses for the various
kinds of failure - FileNotFoundException, RemoteCommunicationException,
etc.
tom
--
If goods don't cross borders, troops will. -- Fr?d?ric Bastiat
---910079544-1933340422-1219740363=:30818--