Skip to main content
3 of 3
added 128 characters in body; edited tags
Christophe
  • 82.2k
  • 11
  • 136
  • 202

MVC: Should View get strings of GUI components directly or should the controller pass strings to View?

I have an MVC application in Java with GUI components in a View class. The GUI has to support two languages, so texts on buttons etc. depend on which language was set at start up. Strings are in .properties files and I have a MyStrings.get(Key) to get the string corresponding to Key.

Should I call MyStrings.get(Key) in my View class constructor or should my Controller class pass the result of MyStrings.get(Key) to the View constructor?

Option1 - The View takes care of strings in its constructor:

View() {
    button.setText(MyStrings.get("BUTTON_TEXT"));
}

Option2 - The View gets the strings from the controler:

View(String buttonText) {
    button.setText(buttonText);
}
Samil
  • 131
  • 5