• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Does local mode need lock&unlock

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
My business logic is in client-side and I code my book() method as sequence:
lock-read-modify-write-unlock
The business logic is in client so that both mode(local or client) use the same sequence. But I saw somebody said that it is not necessary to lock record in local mode.
So my question is: How to write business logic?
What I can think out is:
if(!localMode){
lock()
}
read();
modify();
write();
if(localMode){
db.close;
}else if(remoteMode){
unlock();
}
Am I write? How to seperate lock method between local mode and remote mode?
Thanks in advance!
 
author
Posts: 3252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Jeff Song:
if(!localMode){

Hold it right there. This is what they call a code smell. A bad one.
  • There should be an interface -- call it DataInterface -- which is probably implemented by Data in local mode, and by something else in networked mode.
  • That interface should have clearly defined semantics. A manual, if you like, saying what each method does in abstract terms. In abstract terms, because an Interface is an abstract entity.
  • For example, JavaDoc for the close() method should not say "closes the database". That is what Data happens to do, but Data is but one implementation of the interface. It should not read "In local mode... and in networked mode...", because again you would be thinking in terms of implementations. The abstract meaning of the DataInterface.close() method is after this call, the DataInterface will no longer be used; release all database resources held on behalf of the client. In local mode, that happens to mean closing the database file. In remote mode, that means releasing any locks held on behalf of the client but certainly not closing the database file.
  • Now try to think what the semantics (manual) are for the lock() and unlock() methods.
  • The key point to watch out for is: once the client has a DataInterface object, it should not matter what implementation it happens to have. Whether it is a local implementation, a networked implementation, or an implementation with bad-tempered dwarves throwing axes at each other, it doesn't matter.
  • [list]In an OO design, whenever you find yourself writing code likeThere is probably something wrong with your interface or the semantics you defined for it. Do realise that your test for localMode boils down to the very same thing.[/list]It should be clear by now that your client code will have to lock() and unlock() regardless of the mode. But that doesn't mean that the Data implementations of these methods cannot be empty!
    - Peter
    [ November 22, 2002: Message edited by: Peter den Haan ]
     
    reply
      Bookmark Topic Watch Topic
    • New Topic