In my humble opinion, I don't agree with the fact that the local class and the remote class should not share an interface. Why shouldn't they??? They are supposed to provide the same services, "they must have the same contract with the outside world", so why shouldn't they implement a common interface???
Besides, I believe your approach of having a class which does something like...
public void getRecordCount(int i){
if (remote == true) return remote.getRecordCount(i)
else
return local.getRecordCount(i)
}
goes completely against the concept of
polymorphism. The idea is to eliminate all ifs... If both your classes have the same interface (aka contract), you shouldn't need to do this. In fact, I can see you forward the method with the exact same signature.
I believe
you should probably do something like this...
// Initialization code somewhere
public CommonDataInterface database;
public void initializeLocalDatabase(
String filename )
{
database = new Data( filename );
}
public void initializeRemoteDatabase( some remote rmi params ...)
{
database = find rmi instance of database...
}
From here onwards, all you have to do is call database.someMethod(), and it should work no matter which actual class you are using...
Perhaps the most anti-intuitive reason not to share an interface is that RMI needs all methods to throw a RemoteException and implement the Remote interface. Perhaps in the object-oriented software construction, the local data class shouldn't implement the remote interface and will never throw RemoteExceptions, but you shouldn't be hurt by doing it.
public interface Database extends java.rmi.Remote
{
public mymethod() throws RemoteException, DatabaseException;
}
I also disagree with some people who say that you should wrap the RemoteExceptions in an "adapter" class that rethrows them as other class exceptions, or handles them accordingly. I believe that the code where you call these methods should be aware that they "might" belong to a remote object, and hence, that something wrong in the network might happen. If it happens, catch the exception and display a dialog. Don't worry, it will never happen in local mode...
Hope I didn't hurt anybody's feelings with my ideas, and perhaps I could even help somebody...
Benjam�n