File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Single Bean for all? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Single Bean for all?" Watch "Single Bean for all?" New topic

Single Bean for all?

Rajkumar balakrishnan
Ranch Hand

Joined: May 29, 2008
Posts: 445

Hi friends,

i want to know whether it's a good practice to use a new bean file for each process or i can add a function in the existing bean. For example i put all my setters and getters and functions of login and logout in a single bean instead of two?And i call it from separate servlet file? Which one is a good practice?

Never try to be a hard-worker. Be a smart-worker.
My Blog
Raghavan Muthu
Ranch Hand

Joined: Apr 20, 2006
Posts: 3381

To obtain the less overhead in maintenance, it is always better to segregate/group the related functionality.

Calling it from the Servlet does not really matter but if you do with the database calls for login/logout activities, do have the DAO pattern involved. DAO stands for Data Access Object and it is one of the suggested Design Patterns.

Everything has got its own deadline including one's EGO!
[CodeBarn] [Java Concepts-easily] [Corey's articles] [SCJP-SUN] [Servlet Examples] [Java Beginners FAQ] [Sun-Java Tutorials] [Java Coding Guidelines]
Rajkumar balakrishnan
Ranch Hand

Joined: May 29, 2008
Posts: 445

But what would it really happens when i simply code it using a MVC pattern without DAO and i need as many models as if my functionality my site has 40 kind of functions like login..user details..vendor info...and for each one of them i write a bean file? Will it be a good practice? Could you clarify me!!!
satishkumar janakiraman
Ranch Hand

Joined: May 03, 2004
Posts: 334
If you write a bean for each functionality your classes will be highly cohesive and maintenance of your code will be easy. On the other hand, you will have more classes It is absolutely based on the requirement and your design choice
I agree. Here's the link:
subject: Single Bean for all?
It's not a secret anymore!