*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Worker classes - where to validate data Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Worker classes - where to validate data" Watch "Worker classes - where to validate data" New topic
Author

Worker classes - where to validate data

Dmitri Christo
Ranch Hand

Joined: Jan 19, 2007
Posts: 81
Hello everyone,

I my design I am following a tactic observed several times in this forum: Using worker classes like FileManager and LockManager. This is also followed in Andrew's book. My question is about validating data in one worker class that requires access to the map kept in the other worker class. For example I need to compare the lock cookie passed in update and delete (both FileManager methods) to the lock cookie storage which is kept LockManager.

Similar validation needs to be done in lockRecord() (a LockManager method) which will need to access the record number storage in FileManager.

I looked in the book, but such cross-validation is not happening between these two worker classes, which is why it is ok to declare those maps private in each class.

So in my case I thought instead of making each worker class have a reference to the other (keep clean separation), I could do this validation in my facade class which implements the specification interface and HAS-A both these worker classes.

This would require however to give the maps public or at best default access. Would you say this is a flawed design? Mind sharing any different perspectives on this? Thanks.
rohan tiwari
Ranch Hand

Joined: Sep 13, 2007
Posts: 82
Have a default access method in you file manager or lock manager class and call it from the facade as part of update or delete method.


SCJP 5, SCWCD 1.4, SCJD 5
mohamed sulibi
Ranch Hand

Joined: Sep 04, 2005
Posts: 169
hi;

Similar validation needs to be done in lockRecord() (a LockManager method) which will need to access the record number storage in FileManager.


before calling the lockManager.lockRecord() in facade class call the
fileManager.isRecordExist() (ex) and if the record not exist throw
RecordNotFoundException and don't call the lockManager.lockRecord(),
i think using this idea will deacrease the association between the facade
class (Data class in my project) and LockManager.

and this idea will make you not to pass a ref for facade to LockManager
class.

BR;
Mohamed Darim, SCJP, SCJD in progress ... ( upload 1/april/2008).
Dmitri Christo
Ranch Hand

Joined: Jan 19, 2007
Posts: 81
Thanks Rohan and Mohamed for your ideas.

Basically, what I can see is that, since cross validation is necessary, and I want to avoid associating the worker classes together, validation needs to happen in the facade class. The facade will have references to the worker classes and do all necessary validation.. So the maps have to have default access at best.

If one follows this design, is there another way perhaps? My conclusion, unless I am missing something, is that facade validation is a good tactic.

Another approach could be to merge the two worker classes into one and do all validation there, keeping all maps private, but that would be against good OO design I suppose.
mohamed sulibi
Ranch Hand

Joined: Sep 04, 2005
Posts: 169
hi;


So the maps have to have default access at best

please make it private.

and note that when the facade class do the validation , may be synchronization problems arise , so do more effort to see and solve
these problems.

Best regards.
Mohammed Darim SCJP, SCJD in progress ... (upload 1/april/2008).
Dmitri Christo
Ranch Hand

Joined: Jan 19, 2007
Posts: 81
I think I see what you mean. Instead of dealing with the maps directly, it might be better to create helper methods (with default access) in each of the worker classes. I think I missed this before.

Then, these helper methods will be used in the facade to complete the validation without exposing the maps directly, which can remain private.

Thanks!
 
GeeCON Prague 2014
 
subject: Worker classes - where to validate data