Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Does local mode need lock&unlock

Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
My business logic is in client-side and I code my book() method as sequence:
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:
}else if(remoteMode){
Am I write? How to seperate lock method between local mode and remote mode?
Thanks in advance!
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Jeff Song:

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 ]
    I am not young enough to know everything. - Oscar Wilde This tiny ad thinks it knows more than Oscar:
    Thread Boost feature
      Bookmark Topic Watch Topic
    • New Topic