Let's go back to the original description of the design pattern:
- Model classes are used to represent knowledge and data. A model can be represented as a single object or structures.
- View classes are used to represent the data to the user.
- Controller classes are used to validate input from the user, passing it to the model layer.
Now, there's a word that isn't properly defined: user. Usually, when we program applications and algorithms, the user is the human being at the other end of the program. This definition is misleading, as it perpetuates the idea that there should always be a human being inputting information into the controller, and that views are always graphical interfaces.
I would like to challenge this assumption and from now on, we will define a user as follows: the program or human being that consumes the output of the view layer. As such, part of the view layer can be a JSON or XML represented view, or a raw view, with pure data printed on-screen.
We can now rewrite the definition as follows:
- Model classes provide an internal representation of a component, as well as its ability to be loaded, restored, or persisted.
- View classes provide an external representation of a component that is consumable by another entity.
- Controller classes provide an entry point for external entities to interact with the model safely, and provide a view representation for feedback.
Finally, I will argue that the MVC pattern can be nested in itself. For example, the view layer can be represented by a model, a controller and a view. This last argument should not surprise you, as iOS and macOS both have NSViewController and UIViewController classes at the core of their UI frameworks.