Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring 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

Trouble understanding the logic

Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I`m having trouble with the whole logic of the file. I have implement the following class

now my problem, to for instance update a record i have to provide a cookie.
but i can only get a cookie if i execute lock(recno). so should i create another class, implement the exact same methods and then have something like the following code??

would this be right, or should i have the lock/unlock in my main data class. They way i`m doing it will work, but i does`nt look right.
using sun`s provided interface class then i create my own class
that implements that class, and now i`m creating a third class that looks they same as the sun interface class to actually lock,update,unlock.

Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Derick,

OK... what you are describing is creating a proxy class on the server which has the same methods as Data but without the lock/unlock method - in other words you are hiding the need to lock/unlock from clients.

I know from reading other threads that people have passed the exam by following this strategy, although I personaly do not like it. My problems with it are twofold. First off, by hiding the lock/unlock from clients you are enforcing a locking strategy. This may be OK for the scenario we are given but who knows what locking strategy future clients will want/need to enforce? Secondly, I may be wrong but if Sun felt it important enough to include the cookies in the method signature, this says to me that they too important to hide at the first opportunity.

Your alternative is to pass the resposibilty for the locking through to the client, who must of course follow the (documented) need to follow the lock/update/unlock procedure.

These are just my thoughts on it, although I would say that you should go with whichever method you would be most comfortable justifying/defending.


Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The option of passing the locking responsibility to the client brings a lot of complexivity to the application. Once you follow that strategy, you should track inactive/disconnected clients, in other words, make your server stateful.
On the other hand, by using a proxy or a facade you make the locked operations atomic, which release you from the need of mantainig conversation state with the client, makes your life easier, the application simplier, and once you'll want to change the locking strategy, you can switch the facade, or get rid of it totally.
author and jackaroo
Posts: 12199
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Derrick,

I think you have missed the value of the lock methods: specifically they are there to stop two clients from booking the same record.

Consider the following scenario:
  • Client A requests a list of all records
  • Client B requests a list of all records
  • Client A can see that record 5 is not yet booked
  • Client B can see that record 5 is not yet booked
  • Client A updates record 5 to book it
  • Client B updates record 5 to book it

  • In this case, there was nothing to stop the two clients booking the same record.

    So how are you going to stop this? I am leaving this as an exercise for you - we will eventually get to a solution where locking works for you .

    By the way, could you please remove those ll's from your displayed name to meet the JavaRanch Official Policy On Displayed Names, which requires your displayed name to be a real name. You can change it here.

    Thanks and regards, Andrew
    When I was younger I felt like a man trapped inside a woman’s body. Then I was born. My twin is a tiny ad:
    Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
      Bookmark Topic Watch Topic
    • New Topic