Take the 2-minute tour ×

Let's say I have "settings" classes in my controllers and models, in my Java/Spring/MVC webapp. Now, in both /controllers/ and /models/, should I...

1) ...name them both Settings.java?

2) ...name them SettingsController.java and SettingsModel.java or something similar?

I'm curious about typical naming conventions as well as naming conventions used in your personal experience that worked well. Feel free to reference your own webapp project in place of my, perhaps poor, example.

This is my first MVC webapp, and I'm trying to get a feel for it.

share|improve this question
add comment

6 Answers

up vote 5 down vote accepted

I'd suggest you to call your controller SettingsController and model just Settings. It is because model actually contains you data. What kind of data does your model contain? The answer is: settings. So, call it settings.

Controller is different story. It is a class that deals with you data. There are probably many classes that deal with settings: SettingsBuilder, SettingsFactory, SettingsUtil, SettingsService etc. This one is controller, so call it SettingsController.

share|improve this answer
Overwhelmingly this appears the be the correct answer, and it makes complete sense. Thank you. You've just expanded my understanding of MVC. –  Matthew Doucette Jan 27 '12 at 19:37
You are welcome –  AlexR Jan 27 '12 at 20:12
add comment

Since model classses describe 'real-life' entities it's better to call them by name, so in your case it would be Settings.java.

Controller, on the other hand, is just a byproduct of using specific architecture (MVC) so it gets the Controller suffix, and in your case becomes SettingsController.java.

If you did your application using jsf, for example, you could still have Settings.java as model, but SettingsBean.java as a controller (obviously that's just another convention and you could call it however you like).

share|improve this answer
add comment

Name them SettingsController.java and Settings.java

share|improve this answer
add comment

I'd opt for Settings.java and SettingsController.java.

*Controller follows Spring's convention of controller naming. Furthermore it lets the programmer understand immediately what the class does.

Generally I always plump for simple names for POJO's, Settings.java seems to fit the bill here.

share|improve this answer
add comment

I think the following style is most coherent

               +-  SettingsController.java
               +-  Settings.java

The reason is that Settings is a name describing exactly what it is, while SettingsController describes that it's a controller working on Settings objects.

share|improve this answer
I agree with your naming, but disagree with the package structure - I'd have them both in the same package, or at least under the same package tree. But that may be a matter of preference as well. –  Rob Hruska Jan 27 '12 at 19:17
@RobHruska we have it set the same way, with com.subdomainname.controllers and com.subdomainname.models, and this is the structure the company I work for uses, so I have to follow along. –  Matthew Doucette Jan 30 '12 at 18:03
add comment

I have to agree with the previous posters, Model should just be the name of the entity, and then anything that adjective should be a suffix of the entity, so Settings and SettingsController This is the tact I take quite often. I also use settings as the name of the webpage as well.

share|improve this answer
add comment

Your Answer


