jQuery in Action, 3rd edition
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Package Design Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Package Design" Watch "Package Design" New topic

Package Design

Jerry Ju

Joined: May 26, 2008
Posts: 7
Hi guys, Here Jerry again.

I have one more question.
Listen, I'm done my Data class which implements DBAccess.

And I want to make a business class to wrap the Data class.
so that I try to use it both standalone and network.

I made a interface which included booking, search method.
and I would implement LocalBusiness and RemoteBusiness.
LocalBusiness directly use Data class.
RemoteBusiness is just adaptor for LocalBusiness.
when the client is executed in standalone mode then I just use LocalService.
when the client is executed in network mode then I use RemoteService.

Please note to me If there is something that I missed. ^__^

Thanks for regards.

Primary Java Developer.<br /> <br />Living in Korea. I hope to meet lots of friends over the internet.<br /> <br />Thanks for all guys in this site who helped me to get a SCJD. <br />Cheers !
Roman Yankin
Ranch Hand

Joined: Aug 27, 2008
Posts: 47
Hi Jerry,

The code you have submitted will not compile because method signatures in your Service interface reference RemoteException and this exception is checked exception, thus methods in your LocalService class have to reference that RemoteException as well, which is wrong. I believe you need to think how to resolve that problem
Jerry Ju

Joined: May 26, 2008
Posts: 7
Hi Roman.

Thanks for replay.

It doesn't occure any compile error.
And compile error is not important in that code, most important thing is architecture.

please focus on that one. ^__^
Justin Rundle
Ranch Hand

Joined: Mar 26, 2008
Posts: 123

And compile error is not important in that code, most important thing is architecture.
In my opinion making use of the decorate design pattern to encapsulate your LocalServiceImpl object in your RemoteServiceImpl is a great idea. More so I have designed a similar service/business layer.

More so I think a major advantage is the all your business logic only exists in one place (LocalServiceImpl) which is neat and clean design and further promotes ease of maintainability.

I think you're on the right track!
Roman Yankin
Ranch Hand

Joined: Aug 27, 2008
Posts: 47
Sorry, yes, you are right there are no compile time errors... so, from the architectural point I don't think it is a good idea to implement both LocalService and RemoteService from the java.rmi.Remote interface, thus you say "LocalService is a Remote" class. This is just my opinion, but I think the decoupling has to be made on interface level not on class level.
Jethro Borsje
Ranch Hand

Joined: Jul 22, 2008
Posts: 100
I agree with Justin, I think it's a good idea! I have implemented the same architecture a couple of days back.

Alex Belisle Turcot
Ranch Hand

Joined: Apr 26, 2005
Posts: 516

I rather did something like that:

The local Service make no use of "Remote", but rather a higher level IOException. I consider extending "Remote" from your local interface to be wrong. You'll find many threads on this if you search on the forum about throwing IOException from your Services class.

Jevgeni Zhukov

Joined: Aug 28, 2008
Posts: 18
My suggestion is:
* Create similar interface as provided by Sun, but with all methods throwing RemoteException in addition.
* Make your implementation of Sun interface to implement this new interface as well.
* Make your remote interface to extend this new interface (then it will be empty)
* As to remote implementation class - initialize Sun's interface with local implementation class.

I agree. Here's the link: http://aspose.com/file-tools
subject: Package Design
It's not a secret anymore!