Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

"DataInterface" in a waste of code in my eyes

 
Tiger Meng
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, everybody!
I notice that candidates often use respectively remoteDataclass and localDataclass which implement a dataInterface. I feel this is a waste of code! becasuse both local and remote class have a instance of data, method call in the two classes is also boring, just look like:
xxx getRecord(yyy){
data.getRecord(yyy);
}
I am really confused with this blue print.
Can i use data class directly in both client and server side? Why not modify the Data class: make the public methods could be RMI called?
thus, local mode get a data refrence directly(because in same VM) ; remote client get a refrence of data by RMI naming service, then it can use it just like in local mode.
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Meng XiaoXi:
I notice that candidates often use respectively remoteDataclass and localDataclass which implement a dataInterface. I feel this is a waste of code! becasuse both local and remote class have a instance of data, method call in the two classes is also boring, just look like:
xxx getRecord(yyy){
data.getRecord(yyy);
}
I am really confused with this blue print.
Well, I can't speak for everyone, but this is certainly not the only (or the best) implementation fulfilling the requirements!
  • The client class implementing DataInterface can be the RMI stub generated by rmic. And even if that's not what you're doing (for example because you are using sockets), it would look a lot more interesting than what you show above!
  • In the Connection approach, the server-side DataInterface implementation implements locking (probably by calling a LockManager); although many methods would delegate directly to the underlying Data, others would be more elaborate.
  • And of course the local implementation of DataInterface is Data itself.
  • Can i use data class directly in both client and server side? Why not modify the Data class: make the public methods could be RMI called?
    Not much modification would be necessary. The class should implement a Remote interface. This is one of the more common approaches taken. Its main weakness is that you cannot fully satisfy the locking requirements without introducing some form of client ID and changing the method signatures to take this ID. A second, minor, problem is that it becomes harder to clean up locks when a client crashes (minor because this is not an absolute requirement for the assignment).
    - Peter
    [ November 28, 2002: Message edited by: Peter den Haan ]
     
    Detlev Beutner
    Ranch Hand
    Posts: 76
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    @Peter
    You wrote:
    Its main weakness is that you cannot fully satisfy the locking requirements without introducing some form of client ID and changing the method signatures to take this ID.

    You can! Think of a proxy pattern with an extra layer: The client works on a DataServer class, implementing the Data interface; this class has the same public methods as the Data class (also implementing the Data interface).
    Now the extra layer: The DataServer has got a DataConnection class (remotely!), and thisclass has different signatures, introducing IDs. So both requirements - a class with the same public methods (that also means the same signature) as the Data class as well as the recognizing of the client on the server side - are fulfilled.
    Hope it helps
    Detlev
     
    Peter den Haan
    author
    Ranch Hand
    Posts: 3252
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Originally posted by Detlev Beutner:
    Peter, You can!
    Yes, that will work, but then Data is no longer the RMI-callable object as MX proposed, so the answer is still no you can't
    Which is not true actually. The answer is yes you can. I've not seen anyone use this method yet, and I do not suggest it would be the best solution. You can write a client-side wrapper class around the remote Data object which keeps track of the locks held by the client. This wrapper class could deal with duplicate calls to lock() or unlock(). No signature changes or client ID needed.
    - Peter
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic