This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
Hi, I've written some code on the RMI server side and now need to generate stubs. My problem is that I know that the stub generation requires that I throw RemoteException. The supplied interface from Sun doesn't do this. Ive searched the knowledge based here, but most topics talke about creating a superinterface that does throw RemoteException and then changing DBMain to subclass this.... but after numerous reads and what I always thought was the case, you can't change the supplied interface from Sun. Currently thinking of a way around this, so any help or pointing in the right direction would be appreciated.
Since I don't like one word answers to questions, here is a little more detail:
In this case, you could have an interface that looks similar to the supplied Sun interface however all it's methods do throw RemoteException. A class that implements this interface could be extremely simple: it would just call the relevant methods of the Data class - in effect, adapting the interface to the format you require.
I have still kept this vague. Have a think about it, and come back with further questions as required.
Hi. Yes, thanks .. I've sorted it. Basically, I created a further class that has an instance of the interface within it. The new class doesn't have the RemoteExceptions within it's methods, but the interface then references the methods that do have the RemoteExceptions (what's returned from rmi server). I've then repeated the methods of the interface within the new class without RemoteException and called the equivalent method in the interface reference...thus achieving my requirement. Is this your definition of Adapter ? This certainly resolves my problem by keeping the client side of the solution still referencing DBMain for remote and local versions.
Joined: Dec 29, 2004
I do not understand your explanation of your design completely.
The simplest solution (I think) is:
(assumption: the interface given in the assignment is called DBMain)
Data implements DBMain
Adapter is a new class that has the same interface as DBMain, except for RemoteException that has been added to all methods