This is a very simple example of MVC architecture
Basically, MVC architecture involves 3 parts:
- A Model class which stores and manipulates data
- A View class which listens to events, displays and generates new data from those events
- A Controller class that links the Model to the View. This ensures that the model can communicate to the view without directly modifying any object in the view
This app uses MVC architecture to display click counting of a button.
The Model stores the data which the controller collects and gives to the View.
The view then displays that data and also generates data from click events which is collected by the controller and relayed to the model.
Here's the app on codepen
- The model stores data and has methods for altering data
- The view displays data and has event listeners which generate data
- The controller connects the model to the view. It's the channel which the model uses to send data to the view. It's also the channel in which the view sends new data to the model.