• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Preventing access of DAO layer from Service layer.

 
chets patel
Ranch Hand
Posts: 77
Eclipse IDE Redhat Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I have question regarding DAO design pattern.
Generally we separate service layer from database layer by interface like DAO.
e.g


Now I will acccess the DAO class from the service layer as follows.


My question is as all of my DAO classes are public I can even access it from VIEW layer also.
How can I prevent the DAO access from Viwe layer.
Please help. I am very much confused.

 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just don't use them on the view layer. Or don't expose them to the view layer: not knowing what your view layer is makes it harder to help.
 
chets patel
Ranch Hand
Posts: 77
Eclipse IDE Redhat Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi David
Thanks for your fast response..
How can I prevent them from exposing to View layer?
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Depends on the view layer. You may not be able to, if the view layer can instantiate arbitrary classes, at least not without some trickery. Which cannot possibly be worth it in almost all situations. What are you so afraid of that you must absolutely restrict access to your app's classes?
 
chets patel
Ranch Hand
Posts: 77
Eclipse IDE Redhat Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
one solution I found is if I use the Factory design pattern for DAO layer....I can prevent the access to DAO classes...
is that ok?
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How does that prevent access to the DAO classes? Couldn't I just instantiate one in the JSP using a scriptlet or tag?

What *specifically* are you trying to accomplish?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic