DataBaseInterface - All public Data methods etc Good.
RemoteDataBaseInterface � Locking method definitions Not so good. Ideally, the client application should be completely unaware whether the database he's talking to is local or remote. That means two things. First, the lock() and unlock() methods should always be there - in local mode, they can simply be no-ops. Second, the method calls may throw RemoteException - in local mode, of course, they simply never will.
This would suggest a design like:
DataBaseInterface - All public Data methods including locking and methods that may throw RemoteException
Data Class implements DataBaseInterface � Take out locking methods
LocalDataImp extends Data Class implements DataBaseInterface This looks confusing. Data
is the local implementation of DataBaseInterface, why have a separate LocalDataImp?
RemoteDataImp extends Data Class implements RemoteDataBaseInterface This is misguided. Data implements local database access. Your proxy object implements the same interface but definitely should
not extend Data. If you're using a local proxy class, then
RemoteData implements DataBaseInterface
would do a fine job. If you're using RMI and implement the class remotely, then you'd use
RemoteDataBaseInterface extends DatabaseInterface, Remote
RemoteData extends UnicastRemoteObject implements RemoteDataBaseInterface
I think there needs to be a RemoteDataBaseInterface because this will throw a different type of exception but I�m not sure exactly. If you use RMI, remote calls can throw RemoteException. This means that the interface implemented by both local and remote database should declare its method to throw this exception. Remember that this does
not imply that the method signatures in Data have to be modified; it is perfectly fine for an interface implementation to throw fewer (or narrower) exceptions than the interface declares.
I'm also undecided as to where I should implement the locking. My take on it was that it shouldn't go in the Data class because there is no need for locking in local mode. Good thinking.
Should it go in the RemoteDataImp class or would it be better to create a separate class implementing the Singleton pattern and all locking taking place there. It should not implement the Singleton pattern. Singleton is one of the most abused patterns around, think twice before using it. I'll leave the reason why as an exercise for the reader
- Peter