"Hi, Amigo!"

"Hi, Bilaabo!"

"You're already a solid programmer. So, today we're going to have a lesson on MVC."

"MVC stands for ModelViewController. It's an architectural design pattern for large applications, where the application is split into three parts."

"The first part contains all of the application's business logic. This part is called the model. It contains the code that does everything the application was created to do. This part is the least dependent on the others."

"The second part contains everything pertaining to displaying data to the user. This part is called the view. It contains the code that controls displaying windows, pages, messages, etc."

"The third part contains the code that processes user actions. Any user actions intended to change the model should be handled here. This part is called the  Controller."

"This approach allows you to create three things independently: the program's logic (the model), the mechanism for displaying the program's data to the user (the view), and a handler for user input/actions (the controller)."

"Applications frequently have several views. This is normal. You can view the exact same data in Excel as both numbers and diagrams. In games, you can view events from a first-person, third-person, or map view, plus many others. All of these are different views for a single Model."

"All of the code that decides what to change in the model in response to user actions is gathered into the Controller. For example, if the user decides to close the program, then you need to save the model's data to a file on disk. Or if the user enters new data, then you need to add it to the model. The model will then notify all of the views about the data changes, so they only display the current state of the data."

"Say that again."

"From the perspective of a Java developer, we could say that the model, view, and controller are three groups of classes where:"

"a) each part has its own purpose;"

"b) the relationships between the classes of a single group are very strong;"

"c) the relationships between groups are very weak;"

"d) the ways that the parts communicate with each other are heavily regulated."

"And here's another way to picture it:

MVC - 1

"The model is the most independent part of the system. It doesn't depend on the view or the controller. The model cannot use classes from the view or controller groups(!)."

"The view's primary limitation is that it cannot change the model. View classes can access the model for data or to subscribe to events, but view classes cannot change the model."

"The controller's primary limitation is that it doesn't display data. The controller processes user actions and modifies the model accordingly."

"But why do I need this?"

"The fact that you don't use this right now, doesn't mean that you won't use this in the near future. You're here studying to get a job. And even if this knowledge doesn't prove useful while studying, it will definitely come in handy while working."

"After all, real projects and interviews still await you..."

"We're here talking together now, but perhaps in a month you'll already be working."

"You are absolutely right, Bilaabo. I'll listen to you carefully."

"The MVC pattern is very common in application architecture. You need to know it, so that you don't suddenly start adding view classes to the model because you find that way more convenient."

"The most important thing in any project is its architecture. Your task at this stage isn't so much to be able to create a good architecture, as it is to learn to understand someone else's. You'll still need to grow for a couple of years before you create your own. But you need to understand what other people have created. Right away."

"When an application uses a standard architecture, everything becomes much clearer. By knowing the architecture, you know where things are, how everything interacts, roughly how the program works, where to add a needed class, and where to search for the cause of a bug."

"But, if you aren't familiar with standard approaches to architecture, then even the best architecture won't tell you anything. You'll be like a peasant from the middle ages looking at a new car. A standard car."

"I see. Thanks for the interesting lesson, Bilaabo."

"Finally, here is a good link that you should definitely check out:"

Link to additional material