concept MVC in category gwt

appears as: MVC, MVC
GWT in Practice

This is an excerpt from Manning's book GWT in Practice.

Since the calculator EntryPoint implementation (shown in listing 1.3) places a CalculatorWidget on the RootPanel, we now need to provide this widget. This will be our own widget, composed of basic GWT components. CalculatorWidget will contain the view for our calculator application, a simple data and logic layer as the model, and an intermediary controller between these layers. This, of course, means we’ll be getting our first look at MVC and GWT together—keep in mind that all of these components will end up distributed to the client.

MVC will be the overarching pattern for the macro level of our application. Additionally, we’ll use some other common object-oriented (OO) patterns on other levels because of the general benefits these approaches provide. For example, we’ll use the Observer pattern for event handling as part of the mechanism of communication between our model and our view. We’ll also use the Strategy pattern within the logic and operations parts of our model. We’ll provide more detail about each of these patterns, and the reasoning behind their use in each situation, as we come to those portions of the application.

MVC is a familiar pattern to many developers. The pattern was first described in the late 70s by Trygve Reenskaug, who was working on Smalltalk at the time, and it has since been adopted, in various forms, by a wide range of programmers using many languages. The pattern is intended to separate responsibilities and allow for reuse of the logic and data portion of an application—the model. The view layer represents the model graphically, as the UI. Delegation between these layers is handled by an intermediary that is invoked by the user’s input, the controller. The basic MVC pattern is shown in figure 2.3.

Figure 2.3. A basic model-view-controller architectural pattern diagram. The solid lines indicate a direct association, and the dashed lines indicate an indirect association, such as through an observer/observable relationship.

The key concepts to take away from MVC are the following: the model should be completely unaware of the view and controller, and the pattern can be applied on many different levels within an application.

In MVC, the model can be equipped to alert observers of changes within it, using the Observer pattern (something we’ll look more closely at in section 2.2.3). This is shown by the dashed line in figure 2.3. In this way, any other layer observing the model can react to events coming from the model. Nevertheless, the model does not directly update the view, and this distinction is important. The model is the reusable part in all incarnations of MVC; if the model had any direct knowledge of the view, that tenet would break down. How the view and controller are linked together is often more variable.