aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Remote interface, NetworkedServer and NonNetworkedServer 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 "Remote interface, NetworkedServer and NonNetworkedServer" Watch "Remote interface, NetworkedServer and NonNetworkedServer" New topic
Author

Remote interface, NetworkedServer and NonNetworkedServer

Christy Keane
Ranch Hand

Joined: Mar 29, 2005
Posts: 32
Folks,

in my application, I have a class called NetworkedServer and one called NonNetworkedServer.

Obviously, NetworkedServer is started with the server flag and handles remote requests, and NonNetworkedServer is started in standalone mode and contains no networking code.

They both implement the following interface:


However, the NonNetworkedServer doesn't implement any of Remote's methods, and doesn't use any networking at all.

The reason I implement the Server interface in my NonNetworkedServer, is so that GUI can connect to a Server object, and not care if it uses networking or not.


However, I am worried that I will automatically fail because my NonNetworkedServer implements the Server interface, which in turn implements the Remote interface.

Confused? - I am.

I'ld appreciated any thoughts people might have.
Frans Janssen
Ranch Hand

Joined: Dec 29, 2004
Posts: 357
However, I am worried that I will automatically fail because my NonNetworkedServer implements the Server interface, which in turn implements the Remote interface.


Hi Christy,

I initially had a similar design and I got the same worries. I decided not to take any chances and abandoned this design.

I changed it with a new design, something like this:

Data: implements the given interface

DataAdapter: an abstract class that has the same same method signatures as the given interface (but does not implement it!); all methods are declared to throw RemoteException.

RemoteAdapter: implements DataAdapter and Remote; all methods just call the Data methods

LocalAdapter: implements DataAdapter; all methods just call the Data methods

My business classes were given an instance of DataAdapter, which did not contain any networked-related code if the server was a local-mode server. Minor downside is that the business classes still need to be ready to handle RemoteExceptions, even in local mode, but I stated that that was acceptable in my design document.

Frans.

FWIW, I feel my design was a bit too constructed, only to prevent an auto-failure. The design you are describing sounds much more natural and I surely would have done it that way if it were a real-life project.


SCJP 1.4, SCJD
Christy Keane
Ranch Hand

Joined: Mar 29, 2005
Posts: 32
Frans,

yeah, something similar to your DataAdapter interface is my plan B as well.

It's annoying to have to have to abandon (what I think is)a better design just to avoid the possibility of auto failure though.

Cheers,

Christy.
Jack Gold
Ranch Hand

Joined: Feb 04, 2005
Posts: 85
Christy,
Frans' design is roughly desribed in Max's book. If you do not have it, I would suggest buying it. It will keep you from straying too far from an acceptable solution.

While design is probably the most gratifying part of what we do, I believe one gets more mileage from imitating a proven design than by cooking up their own.


SCJP 1.4<br />SCJD <br />SCWCD (Studying)
 
Don't get me started about those stupid light bulbs.
 
subject: Remote interface, NetworkedServer and NonNetworkedServer