MVC’s three classes myth
Model View Controller is a graphical interface design pattern that aims at ensuring separation between the presented thing and its presentation by loosely coupling them with a controller. The primary benefits of this are the ability to modify one side with minimal impact the other (the controller providing the flexibility required). It also enables a single thing to support multiple representation of itself. Finally it enables composition of smaller elements designed in this way into larger interfaces. This last part is mostly theoretic in many cases.
I was trained using the PAC model which is close enough to be deemed a variety of MVC. What I was taught is that although there are three conceptual parts in a GUI, this does not assume any implementation. Let alone an object oriented one. So why do we feel compelled to have at least three classes named (more or less) Model, View and Controller ?
I believe there are at least two reasons for this.
The first one is that many among us are not that confident in GUI development. We tend to either overlook it as not important or we find it to cumbersome and boring to pay too much attention to it. So instead of thinking well about we are doing we try to apply a well known recipe, I mean pattern, blindly. This attitude leads in turn to more complex code, not as much re-factoring or testing than in other places, less design effort devoted to it. The final result being that GUI is difficult to develop, hard to maintain and is generally painful to produce. This, in turn, entirely justifies the original behaviour.
The second reason is that it is easier to explain to people (developers, management…) that are not familiar with GUI development. It is much simpler to say that you follow a MVC pattern, here is the Model, here is the View and here is the Controller than try to explain that Model and View are fairly easy to identify but that the controller is actually composed of a myriad of listeners, callbacks, small coordination classes, glue code and such. It is even harder to explain that part of the Controller is implemented in a class called Model and another part exists in a class called View.
So basically, everyone is happy and that is why we should continue to do it (which I have to admit is not the conclusion I had in mind when I started this article). However, we need to remember this is largely a myth (or a tale), that the reality is different and that we need to plan, design and act based on reality.
As always, comments are very welcome.