title: How do I create a flexible MVC structure?
body: <p>As part of the training scheme I am on at the moment, I have been tasked with developing a simple command-line based helpdesk application. The point of the project is to develop our abilities to use design patterns, SOLID principles, MVC architecture etc.</p>
  
  <p>I am having problems with understanding how to keep my MVC structure flexible. Here is a sample of one part of my code...</p>
  
  <pre><code>public class RegisterController 
  {   
      View view;
      RegisterModel registerModel;
  
      public RegisterController()
      {
          registerModel = new RegisterModel();
      }
  
      public void processRegistration(String username, String password, Role role)
      {
          if(registerModel.isRegisterable(username, password))
          {
              User newUser = new User(username, password, role);
              registerModel.registerUser(newUser);
              view = new LoginView(new LoginController());
          }
          else
          {
              System.out.println("ERROR during registration.");
              view = new MainView(new MainController());
          }
  
          view.startView();
      }
  }
  </code></pre>
  
  <p>I ideally want to be able to go in at a later date and substitute it with a different user interface (view classes) e.g. a web page, without altering my model or controller. However, at the moment you can see that I am coding to a concrete implementation of my command line "MainView" and "LoginView" classes.</p>
  
  <p>How can I make this controller code more flexible and allow substitution with a different user interface with minimal code modification? Is it unrealistic to expect the controller code to remain the same when changing to a different UI?</p>