The model represents the part of the application that implements the logic, manages the data and defines the behavior of the application. The model responds to:
- the view information requests about its state updating it
- instructions to change state from the controller.
The View reproduces the contents of the model. It specifies exactly how the model data should be presented. Whenever the model data changes, the view must update its representation as needed.
The controller is responsible for handling the user requests. It is the link between the client and the system and ensures that all the resources needed for completing a task are delegated correctly.
Once the controller knows which action needs to be performed it delegates the rendering process to the View layer.
In other words, the user uses the controller. The controller manipulates the model. The model updates the view that the users sees after a specific request.
Regarding the implementation, you can have one class for the controller that holds a reference to the model manager class and invokes the methods on that object reference depending on the user requests. For example:
case "List":
view.show("" + model.getAll());
break;
case "Add":
String input = view.get("title");
String input1 = view.get("artist");
String track1 = view.get("Track title");
String track2 = view.get("Track artist");
if (input == null) return;
String msg= "";
view.show(msg);
CdTrack cdTrack = new CdTrack(track1, track2, new Time(0,0,0));
CdTrack[] cdsTrack = {cdTrack};
model.addCd(new Cd(input,input1,cdsTrack));
view.show(msg);
break;
The view class should pass the request to the controller. For example:
@Override
public void actionPerformed(ActionEvent e)
{
if(((JButton) e.getSource()).getText().startsWith("List"))
controller.execute("List");
if(((JButton) e.getSource()).getText().startsWith("Add"))
controller.execute("Add");
}