This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Servlets and the fly likes Java Bean Class Name Convention Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Java Bean Class Name Convention" Watch "Java Bean Class Name Convention" New topic
Author

Java Bean Class Name Convention

Michael Lynch
Greenhorn

Joined: Dec 21, 2011
Posts: 5
Forgive me if the Servlets forum isn't the appropriate place to put this post - I couldn't make up my mind which was best...

Curious what everyone thinks about naming conventions for JavaBeans. I'm working on my first Java web application, and I found myself making classes called, for instance, ErrorBean, LoginBean, MenuBean, etc. when the class is being used mostly to feed data to the view. For example, LoginBean provides logic and properties to display a login or logout link with the appropriate URL (based on the current state of the user account backend). On the other hand, classes I created which I consider more a part of the real model, such as Player, Team, Pick, Bowl, Pool (I'm making a college football bowl pool application), don't have the 'Bean' suffix. To a degree, I made these naming choices without much thought, and I think I probably just saw some examples of adding 'Bean.' I'm curious what the convention is, or if there's a good reason to keep this up.

Until the last half hour or so, I had been thinking of the *Bean classes as being part of the View, not the Model. Now I'm thinking I was wrong and that they are, in fact, part of the Model - just not the part of the model that relates to the real business task at hand. Do you agree that these classes that are almost purely created to ensure I can keep scriptlets out of my JSPs are part of the Model?

Thanks for your input, forum goers!
J. Kevin Robbins
Ranch Hand

Joined: Dec 16, 2010
Posts: 633
    
    7

I follow the same convention, and I also suffix DAO onto all my DAO objects. Remember that you can also use your package naming to keep things organized such as com.mypackage.model.bean and com.mypackage.model.dao.

I also consider beans part of the model layer because they work in conjunction with the DAOs at the data layer and would do so even if the view was a Swing app instead of a JSP. Remember separation of concerns; your beans shouldn't know or care where they are going to end up.

That's just my two cents worth.

"There is no reason for any individual to have a computer in his home" ~ Ken Olson, Co-founder of DEC, 1977
Michael Lynch
Greenhorn

Joined: Dec 21, 2011
Posts: 5
I was totally unaware I was even following a convention, so it's good to know that I apparently have reasonable instincts.

Still interested in other views if anyone else has something different to say... I appreciate the advice thus far.
J. Kevin Robbins
Ranch Hand

Joined: Dec 16, 2010
Posts: 633
    
    7

I'm not sure if there is a "convention" either. This is just the system I devised because when I'm looking through a project with dozens or even hundreds of files, I want to be able to tell what they are for without opening each one.

I'm not shy about using long file names. I'll use names like "CurrentActiveEmpDataBean.java" because it drives me crazy to be maintaining code with file names like "ctacemdt.java". I mean, c'mon, drive space is cheap and we left 8.3 file names behind a long time ago.
 
 
subject: Java Bean Class Name Convention
 
Similar Threads
One view/controller, pluggable models
different method name
Where's managed bean on MVC?
on UI design :(
My SCEA Part 1Study Notes