The controller

The controller manages communication between the view and the model. It also encapsulates the functionality that is specific just to governing the interaction between various logical components, as a result of which model and view subsystems remain decoupled. The controller can be termed as the binding element between the model and views.

The software virtue that MVC exhibits is modularity, which helps developers to manage the complexity of developing an application. It allows the model, view, and controller modules to focus on a limited range of functionality. In short, it allows them to specialize. 

As a general rule, the modular design is preferred over a holistic one.

MVC is unique among the patterns that we have looked at so far in its general applicability. It was originally introduced in SmallTalk in the '70s, and it is language- and platform-agnostic. The model view controller design pattern may be applied to the development of any application that supports a graphical user interface or GUI. We will illustrate MVC with an example from the physical world.

Let's take the example of an old-school landline telephone. The key functionality of this device is a subsystem that physically connects to the line leading to the home or business and transmits and receives signals to and from that wire. Since this is the core of what a phone does, we will call this the model. The interface for very early phones was a horn-shaped microphone mounted on the front of the device and a speaker that the user had to hold next to their ear. Later, the interface evolved so that the speaker and microphone were integrated into a handset and dialling a number evolved from speaking to an operator to dial router and later to a keypad. Though there is no screen, the speaker and the microphone are an interface. So they are analogous to the view. The controller in this example will be the other parts required to complete the device, for instance, the casings, the connections between interface elements, and the core phone components. In the '70s, the core phone functionality, that is, the model was integrated to a new device. This one coupled the line communication hardware to an interface that modulated binary signals into one suited for telephone systems, that is, one in the human auditory range. This new device was the dial up modem. The analogy is telling, in that, it is the core phone or model functionality that endured largely and remained unchanged for long. Likewise, in the software world, interface subsystems tend to be changed the most, driven by user feedback and evolving interface styles and standards. In the upcoming sections, we will work with simple MVC examples to dig into the concept a little more.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset