Model-View-Controller (MVC) Architecture - BunksAllowed

BunksAllowed is an effort to facilitate Self Learning process through the provision of quality tutorials.

Community

Model-View-Controller (MVC) Architecture

Share This

MVC is one of the widely used design patterns in the domain of web application development. In this article, we'll talk about the basics of MVC, and its advantages along with examples in Java-based web application developments.

Basically, MVC is a way to structure your application in such a way that different components are segregated properly. This architecture was initially included in the two major web development frameworks - Struts and Ruby on Rails.

In MVC architecture different responsibilities of an application are divided into the following:

Model: used to handle data and implement business logic.
View: presents the data generated for users according to the requests.
Controller: processes user requests and fetch necessary resources.

Each of the components has a demarcated set of tasks which ensures smooth functioning of the entire application along with complete modularity. Let us have a look at each of these components in further detail.

Controller

The controller performs coordination between the model and views to process a user request.

The primary function of a controller is to call and coordinate with the model to fetch any necessary resources required to act. Usually, on receiving a user request, the controller calls the appropriate model for the task at hand.

Model

Simply, the model is the data for our application. The data is modeled in a way that it's easy to store, retrieve, and edit.

Whenever a user makes any request for the controller, it contacts the appropriate model which prepares data based on the user request. A model contains the logic to update the relevant controller whenever there is any change in the model's data.

View

The view is responsible for rendering the data received from the model. There may be pre-designed templates where you can fit the data, and there may even be several different views per model depending on the requirements.



The Advantages of the MVC Architecture



A common problem faced by application developers these days is the support for different types of devices. The MVC architecture solves this problem as developers can create different interfaces for different devices. The controller can select an appropriate view. The model sends the same data irrespective of the device being used, which ensures complete consistency across all devices.

The MVC beautifully isolates the view from the business logic. It also reduces complexities in designing large applications by keeping the code and workflow structured. This makes the overall code much easier to maintain, test, debug, and reuse.




Happy Exploring!

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.