MVC (model view controller) pattern is a popular pattern that makes easier to deal with programs that have databases. Although it is widely used in PHP, Java, and other modern programming languages, it is hard to find a simple explanation with simple example source code. So the purpose of this post is to explain MVC pattern with simple source code.
The view is responsible to display data in a specific format, usually in user interface. View accepts data from the model and display the data somewhere and somehow (to the user). We can consider the view as a receptionist who shows and explain data to guests.
The model is responsible to manage data (usually to save data or retrieve necessary data from a database). It stores data in a database and retrieves data from a database. We can consider the model as a warehouse specialist who deals with every data of a database.
The controller is responsible to handle view and model layers to work together. The controller receives a request from a client and invokes the model to fetch requested data and sends the data to the view. We can consider the controller as a supervisor of the view and the model.