aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes My design works perfectly but is it ok...? 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 "My design works perfectly but is it ok...?" Watch "My design works perfectly but is it ok...?" New topic
Author

My design works perfectly but is it ok...?

Ricardo Estafan
Ranch Hand

Joined: Mar 29, 2004
Posts: 84
Here is my design :
Data ------implements------ DBAccess(Interface given by Sun)
Database ---------implements--------------- DataAccess
(holds DBAccess to make calls to Data) (extends Remote)

DatabaseRMIImpl ---------implements--------------- DataAccess
(holds Database to make local calls) (extends Remote)
(extends UnicastRemoteObject)
Client
(holds DataAccess which is either local or Remote returned by factory)
It all works but i'm not quite sure on the part where the local Database implements the clientinterface DataAccess which extends remote.
What patterns do you recognize?
Thanks a lot it's a big help!!
George Marinkovich
Ranch Hand

Joined: Apr 15, 2003
Posts: 619
Hi Ricardo,
Originally posted by Ricardo Estafan:
It all works but i'm not quite sure on the part where the local Database implements the clientinterface DataAccess which extends remote.
What patterns do you recognize?


Looks like the classic Object Adapter design pattern (Gamma, et al., Design Patterns, p. 139). Target -> DataAccess, Adaptee -> DBMain, Adapter -> Database. Clients call operations on a Database (Adapter) instance. In turn, Database (Adapter) calls DBMain (Adaptee) operations that carry out the request.
But here are some questions:
1) If Database adapts the DataAccess interface to the DBMain interface for the purpose of supporting local database access, then why does DataAccess need to extend Remote?
2) Do you really want to say that your local database access interface can throw RemoteExceptions?


Regards, George
SCJP, SCJD, SCWCD, SCBCD
Ricardo Estafan
Ranch Hand

Joined: Mar 29, 2004
Posts: 84
Hello George,
Do you mean that i need two interfaces
one for handling local
and one exactly the same as local, but throwing remote extending remote ,which i only implement in DatabaseRMIImpl. ?
Thanks for the help!!
[ April 06, 2004: Message edited by: Ricardo Estafan ]
Ricardo Estafan
Ranch Hand

Joined: Mar 29, 2004
Posts: 84
Or perhaps anyone else can respond to this?
Thanks for the help, it is very appreciated
Denis Spirin
Ranch Hand

Joined: Mar 22, 2004
Posts: 72
Well, I have similar question. In instructions.html we find:
Your data access class must be called "Data.java", must be in a package called "suncertify.db", and must implement the following interface:

(DBMain interface). I've seen thread where IO and locking is processed by Data class. In fact, the only "must" here is that Data must implement DBMain. I think, mixing all in one Data class is not good idea. But may be, "must implement" means that we really have to provide full functionality to all methods mentioned in interface?
In my assignment I use similar design:
1. Data implements DBMain (DAO). Methods lock, isLocked, unlock and find have no bodies, and their functionality stands with different classes (lock manager, local and remote databases).
2. LocalDatabase and RemoteDatabase (Decorators) implement DatabaseInterface and contain Data object.
What do you think?


Regards<br /> <br />Ph.D.<br />SCJP 1.4, SCWCD 1.4, SCBCD 1.3, SCJD 2
Stephen Galbraith
Ranch Hand

Joined: Oct 27, 2003
Posts: 90
I get neverous when I see partial implementations. I mean to say that by saying that Data implements DBMain I've agreed to the contract that DBMain implies and any reasonable (and we have to be careful what reasonable means!) person would expect when they see your Data implementing DBMain, that the Data class does indeed have this functionality.
Perhaps data can farm this out to other classes to actually do (so for example, the lock actually gets called by myLockManager.lock() or something), but should Data not be "complete" ?
This is more my view of what I'd assume as a lazy programmer seeing that contract implied in the interface, I'm sure there are others!
Steve


SCJP 1.4, SCJD, SCWCD 1.4
Denis Spirin
Ranch Hand

Joined: Mar 22, 2004
Posts: 72
Perhaps data can farm this out to other classes to actually do (so for example, the lock actually gets called by myLockManager.lock() or something), but should Data not be "complete" ?

Yeah, you are right. I felt that implementing "empty" methods is not good idea.
Thanks a lot!
Ricardo Estafan
Ranch Hand

Joined: Mar 29, 2004
Posts: 84
Could somebody please answer my question on needing to implement two interfaces one for handling local and one exactly the same as local, but extending remote ,which i only implement in DatabaseRMIImpl. ?
Thanks for the help!!
Ricardo Estafan
Ranch Hand

Joined: Mar 29, 2004
Posts: 84
I've been reposting in this one for a week now could somenone please have a look at my question... :roll:
Thanks a lot!!
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11460
    
  94

Hi Ricardo,
Having two separate interfaces will certainly work.
On the client side you could use the Proxy pattern to hide the remote interface - this would allow the remainder of your client application to work with just the generic DataAccess interface.
You could also use the Factory pattern on the client side to further abstract this.
Regards, Andrew


The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: My design works perfectly but is it ok...?