aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes gui controller and remote interface Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "gui controller and remote interface" Watch "gui controller and remote interface" New topic
Author

gui controller and remote interface

Dmitri Christo
Ranch Hand

Joined: Jan 19, 2007
Posts: 81
Hi,

after finishing the rmi (remote) part of the assignment, I came across an interesting issue. I am reading Andrew's book in parallel and have gotten several good design ideas from it.

When he designs his controller like this:


I notice that all of the above 3 implementations: direct, rmi and sockets are instantiated against the same interface DBClient and subsequently all handled in the same GuiController class. In my case that interface would be the original interface supplied by Sun.

However since the interface supplied to me did not throw RemoteException, I opted for the adapter pattern when creating my remote interface. So my remote implementation can only be instantiated against the remote interface, say DBClientRemote.

I was wondering if anyone had a suggestion/idea how to have one GuiController class that can handle two interfaces, DBClient and DBClientRemote, avoiding duplicate code. Or do you see any flaws in my suggested approach?

Many thanks
Oguz Ozun
Greenhorn

Joined: May 10, 2007
Posts: 19
Originally posted by Dmitri Christo:
Hi,

after finishing the rmi (remote) part of the assignment, I came across an interesting issue. I am reading Andrew's book in parallel and have gotten several good design ideas from it.

When he designs his controller like this:


I notice that all of the above 3 implementations: direct, rmi and sockets are instantiated against the same interface DBClient and subsequently all handled in the same GuiController class. In my case that interface would be the original interface supplied by Sun.

However since the interface supplied to me did not throw RemoteException, I opted for the adapter pattern when creating my remote interface. So my remote implementation can only be instantiated against the remote interface, say DBClientRemote.

I was wondering if anyone had a suggestion/idea how to have one GuiController class that can handle two interfaces, DBClient and DBClientRemote, avoiding duplicate code. Or do you see any flaws in my suggested approach?

Many thanks


Hi Dimitri,

Maybe, you should create another interface (for the services exported by the server to the clients) and in this interface, you should declare IOException (super class of RemoteException) for the methods put into this new interface.

Actually, this is what I did to eliminate duplicate codes and satisfy the constraints coming from supplied interface in the assignment.
Dmitri Christo
Ranch Hand

Joined: Jan 19, 2007
Posts: 81
Hi Oguz,

thanks for your suggestion. I always was under the impression that the interface supplied by Sun, was the "highest" level of abstraction and everything else should be built around it. That interface throws only RecordNotFoundException, SecurityException, and DuplicateKeyException which will be implemented by us.

Would you mind explaining a little bit further about that additional interface you are mentioning? I also found that interesting discussion: rmi implementation
..but unfortunately wasn't able to get much out of this, because the best approach there actually catches RemoteException, which I am not sure if it is a good idea. The entire issue here (and in the other discussion) stems from the original supplied interface not throwing RemoteException, thus not being suitable for remote implementations to be instantiated against. That means, remote client would need to call methods to the "adapter" interface DBClientRemote.

Could we be talking about the same "adapter" interface here?

Thanks again
Pavel Kubal
Ranch Hand

Joined: Mar 13, 2004
Posts: 356
Originally posted by Oguz Ozun:


Hi Dimitri,

Maybe, you should create another interface (for the services exported by the server to the clients) and in this interface, you should declare IOException (super class of RemoteException) for the methods put into this new interface.

Actually, this is what I did to eliminate duplicate codes and satisfy the constraints coming from supplied interface in the assignment.


I agree with that, because I did exactly this. Now I'm about to submit.
Dmitri Christo
Ranch Hand

Joined: Jan 19, 2007
Posts: 81
I believe we might be talking about the same thing. I also have a new (second) interface that serves as the remote interface. Every method in there throws RemoteException.

My concern was how to avoid duplicate code in the gui controller when distinguishing between local clients who are calling methods from DBClient and remote clients who are calling methods in DBClientRemote.

Local calls will be handled by
and remote calls will be handled by

I am afraid I might be missing something...So, in the gui controller when the time comes to select between local or remote connection... If I go with this option won't I end up with duplicate code in the controller class?

A little bit more details would greatly help me clear this confusion. Thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: gui controller and remote interface
 
Similar Threads
Apress: RMI Factory Pattern and GuiController
Problem with RMI - encountering null value
cannot run Max' s code
[URLyBIRD] guicontroller problem with interfaces
DBMain method need throw RemoteException?