The MVC (Model View Controller) pattern is not unique to Java, not by any stretch of the imagination.
You often see it in web designs. the idea is to separate out each object into a 3 tier system, very similar to how you would in a traditional 3 tier system.
Controller
The controller works on both the Model and the View, controlling the data flow and keeps the model and view separate.
It does so by listening to events of the application, or outside events, and performing an appropriate reaction to that event. Most often this is by calling a method from within the model, and then updating the view once that operation is complete.
Since the view and the model are connected through a notification mechanism, the result of this action is then automatically reflected in the view.
Model
The model contains just the pure data, no logic whatsoever as to how to display the data. This means it does not care how the view displays, be it REST API, GUI, Console, or even web application. You shouldn’t see anything like System.out.println()
, but instead should only return strings, which the view will take to display.
In some instances, I’ve seen that this is the main class, with business logic contained within it. In other cases, I’ve seen it separated.
View
The View presents a visualization of model’s data to the user. The view knows how to access the model’s data, but it does not know what this data means or what the user can do to manipulate it.
The view can be updated to display information in different manners easily, such as moving between a web app, a JSON output through a REST API, etc.
Advantages
As with a multi-tier application, you can have different developers working on different sections.
Actions can be grouped together.
Models can have multiple views based upon how you want to view the files.
The partition of duties helps the developer in future developments and upgrades.
Disadvantages
The framework navigation can get complicated as there are additional files to work with.
MVC – Model View Controller was originally found on Access 2 Learn
One Comment
Comments are closed.