• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

LockManager & DataManager for different operations

 
Bhavik Patel
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hii guys .. I have created two classes as worker classes that will be used by
Data class that implemetns the DBAccess interface..This approach was taken to separate locking and data related operations separate...

Ok here is my deleteRecord signature ...
and in my spec i have to throw SecurityException if owner can't be verified..

public void deleteRecord(long recNo, long lockCookie)
throws RecordNotFoundException, SecurityException;

I have to check for case for SecuriyException in de;ete method.

so here is the snippest..

reservationMap is static map in Lock Manager that keeps recordnumber and cookie as key value pairs..

but the problem is reservationMap Colletion ....To check the above condition
i am providing static method in the LockManager that can check the above condition and return true or false based on client's identity ...if false then throw security exception..


Ok here is my concern ... Is it ok to call LockManger.isOwner() method from the deleteRecord method inside the DataManager class.??I mean am i violating the separation law here?? by putting this call will make DataManager class depend on LockManager for isOwner method...and the main purpose of keeping them separate will be violated...Is it ok ?? If not what other alternative can be ??

waiting for the ranchers view...
 
Bhavik Patel
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
any thought on this issue ???
 
Simon Cockayne
Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bhaivik,

Why not use a Strategy pattern?

Rather than calling a static method LockManager.isOwner...

...why not:

A) Create a LockManager interface (that includes isOwner()) that LockManager implements.
B) Store a reference to LockManagerInterface in your data class.



That way if you want to change your locking with a new updated class (CrazyLockManager), than as long as it implements LockManagerInterface and you update the reference in your Data instance, the new behavhiour in CrazyLockManager will be used at runtime.

Program to interfaces, not implementations.

Cheers,

Simon
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic