Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

using LockManager method in DataManager

 
Mary John
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I have a question regarding using a method of LockManger in DataManager
my design is pretty much same as that described in Andrews book and follow the facade pattern for the Data class that implements the DBAccess interface.
So Data class calls methods of DataManager class(all read/write/find methods) and LockManager (lock, unlock) methods


My question is can I call LockManager method within methods of DataManager eg update, delete etc? is it against the principle of separation of classes?

pseudocode:

class DataManager{
public void updateRecord(data, recno, cookie)throws securityexception, rnf
{
if(LockManager.isLockedBy(recno,cookie))
throw new securityexception();
//continue update record

}

class LockMananger
{
map of locked records;
lock method returns cookie;
unlock method;
isLockedBy method return boolean;

}
[ April 17, 2008: Message edited by: Mary John ]
 
Eric Ushie
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mary,

With reference to Andrew's book, i think you can call methods of LockManager from your DataManager given your scenario without breaking any rule.
 
Jimmy Ho
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Quick question: Which book is "Andrew's book"? Can someone give the title and author? Thanks.
 
Justin Rundle
Ranch Hand
Posts: 123
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jimmy,

Well actually the author is Andrew... Andrew Monkhouse and Terry Camerlengo and the name of the book is "SCJD Exam with J2SE 5 (2nd Edition)".

Good luck!
 
Cristian Aionesa
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mary John wrote:Hi
I have a question regarding using a method of LockManger in DataManager
my design is pretty much same as that described in Andrews book and follow the facade pattern for the Data class that implements the DBAccess interface.
So Data class calls methods of DataManager class(all read/write/find methods) and LockManager (lock, unlock) methods


My question is can I call LockManager method within methods of DataManager eg update, delete etc? is it against the principle of separation of classes?

pseudocode:

class DataManager{
public void updateRecord(data, recno, cookie)throws securityexception, rnf
{
if(LockManager.isLockedBy(recno,cookie))
throw new securityexception();
//continue update record

}

class LockMananger
{
map of locked records;
lock method returns cookie;
unlock method;
isLockedBy method return boolean;

}
[ April 17, 2008: Message edited by: Mary John ]




Hi Mary John,

I have the same problem as you did. How did you handle it? The solution that you gave is the only one that I can think of, but this make my classes depend of one another...or not?! If I reconsider my thoughts the fact that one class uses the services from another is not a bad thing. I'll probably follow your design.

What do you guys say about that? Any advice? Thanks.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic