Lesson Wednesday

MVC: Model View Controller

This division of labor we talked about in the last lesson where the template only handles displaying information and everything else is handled using routes and classes is something that shows up again and again in web development. Programs written in this way are using what is called a design pattern. Design patterns are very general, reusable solutions to common needs and problems that arise in software development - they can be used like blueprints for writing software in any language.

There are lots of design patterns out there - this one is called MVC, which stands for Model View Controller. In our context, the idea is that each template is acting as a View, and its job is to let you view data. Our Task class is acting as a Model. The Model handles all of the heavy lifting in your program. Its methods handle storing information and manipulating it. Our app.php file is acting as the Controller - the Controller's job is to act as the go-between for the Models and Views. When the user interacts with our program (by going to a URL, clicking on a link or pressing a submit button etc.) it is the Controller's job to use routes to call the appropriate methods on the model and renders the appropriate templates.

Don't worry the MVC design pattern is a very large concept, but you will have plenty of time to get comfortable with it, and plenty of practice too because it's used so often.