Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Ricardo Estafan
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 619
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Ricardo Estafan
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or perhaps anyone else can respond to this?
Thanks for the help, it is very appreciated
 
Denis Spirin
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Stephen Galbraith
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Denis Spirin
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 11944
212
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic