A
Adam
VisionSet said:Consider an object that needs to be accessible over a network, and also
locally. Which do you think is the best design:
1/ Have one interface that declares RemoteExceptions and any other
Exceptions peculiar to the Object. Disadv: The object will never throw a
RemoteException if available locally.
2/ Have two interfaces almost identical except one throws the
RemoteExceptions in addition. Disadv: two interfaces to maintain that must
mirror each other.
I like the 2nd idea:
interface ForRemoteUse
{
void aMethod() throws RemoteException;
}
interface ForLocalUse extends ForRemoteUse
{
void aMethodNoExceptions();
}
class RemoteImplementation implements ForRemoteUse
{
void aMethod throws RemoteException
{
//code
}
}
class LocalImplementation extends RemoteImplementation implements
ForLocalUse
{
void aMethodNoException()
{
try{
aMethod();
}catch(RemoteException e)
{
throw new Error("Local implementation was supposed not to
throw RemoteException at all!!!");
}
}
}
Check out EJBs (remote, local and home interfaces) - i think they are
dealing with the same thing there.
Adam