What is MVC – the simple answer

While wandering around the Internet – I stumbled upon someone asking for a simple explanation of MVC.

This response seemed to sum it up perfectly for me:

The Model is the data source. It’s your database storage, it’s the code needed to add/remove/update/change the information you warehouse. The View is the part the user sees and interacts with. An HTML page, an application window. The Controller is the code that marries the View to the Model. If you clicked a “Delete” button, it handles the business logic and rules (are you the authorized person to delete? is it a deletable record, etc). The View doesn’t need to know anything about the Model. The Model doesn’t need to know anything about the View. The Controller is what marries the information source (Model) with the output (View).

Think of it in terms of video games. Way back when – there were tons of different video cards and how they worked. Games needed all kinds of code to talk to them. You had to choose what kind of card you had before you could play the game. Game developers had to create code for different video cards.

Along comes something like OpenGL or DirectX — and it acted as the middle-layer between them. Game developers could write to the DirectX interface — instead of different card’s instruction sets. It freed game developers from having to know about the specific video card. It freed card makers to be able to design to the DirectX instruction set.

In this case – you, playing the game, is the View, DirectX is the Controller, and the Model is the video card.

This entry was posted in Programming.

Post a Comment

Your email is never published nor shared. Required fields are marked *