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?
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.
"I have a mind like a steel... uh... thingy."
Joined: Dec 21, 2011
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.
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.