• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Worker classes - where to validate data

 
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
reply
    Bookmark Topic Watch Topic
  • New Topic