Model-View-Controller (MVC)
Model-View-Controller (MVC) is a pattern used in software engineering to
separate the application logic from the user interface. As the name implies, the
MVC pattern has three layers.
The Model defines the business layer of the application, the Controller
manages the flow of the application, and the View defines the presentation
layer of the application.
Although the MVC pattern isn’t specific to web applications, it fits very well in
this type of applications. In a Java context, the Model consists of simple Java
classes, the Controller consists of servlets and the View consists of JSP pages.
Here’re some key features of the pattern:
It separates the presentation layer from the business layer
The Controller performs the action of invoking the Model and sending data
to View
The Model is not even aware that it is used by some web application or a
desktop application
The Model Layer
This is the data layer which contains business logic of the system, and also
represents the state of the application.
It’s independent of the presentation layer, the controller fetches the data from the
Model layer and sends it to the View layer.
The Controller Layer
Controller layer acts as an interface between View and Model. It receives requests
from the View layer and processes them, including the necessary validations.
The requests are further sent to Model layer for data processing, and once they are
processed, the data is sent back to the Controller and then displayed on the View.
The View Layer
This layer represents the output of the application, usually some form of UI. The
presentation layer is used to display the Model data fetched by the Controller.