In this blog I am going to do my best to explain the MVC design pattern, this is part of my introduction into web development. MVC stands for model, view control and a design pattern is a reusable solution for commonly occurring scenarios, guidelines if you will. Something to keep in mind is this blog will be a general explanation of the MVC design pattern as it can be implemented in a variety of ways, some design patterns even borrow concepts from the MVC design pattern.

So let's start with the core responsibilities, of the model, view, and controller.

Model

The Model of an application is usually responsible for data-related tasks, this could be something like a database. The model interacts with the view and controller a provides the data to be manipulated and rendered to the user. An example of this in action would be retrieving a customer's info from the database allowing the customer to view or manipulate it.

View

As the name suggests this part of your code will be responsible for the visual elements of your application. The view may be things such as your HTML/CSS, UI’s and other visual elements of your application. In addition to this, our views are also used for template engines, template engines are used to enable us to use dynamic data with our language of choice. With the use of a template engine, we can obtain the logic of our chosen language. For example if we want the use Ruby we can use ERB, if we want to use Javascript in our web app we could use something such as Handlebars.

Controller

The controller is responsible for user input and processing get and post requests (more on that shortly). In short, the controller receives input from the user, gets data from the model and passes it to the view.

A quick explanation of get and post requests

Websites commonly work via The Hypertext Transfer Protocol (HTTP) or the Hypertext Transfer Protocol Secure (HHTPS)(sites with secure communication). When interacting with a website we use a combination of get and post requests, to send and receive information. The client (your browser) makes the get and post requests to a server (where a web app/site is hosted).

Here are a couple of videos I found on the subjects I covered, I will no doubt return to this subject in the near future, thanks very much for reading as always!