This is not an introduction to the MVC pattern, but a look into its implementation in Smalltalk-80 to understand the original intent and function of the Model, View, and Controller triad. Starting with the “classic” MVC helped me understand the evolution of the presentation patterns that came after it. We will look at how a simple MVC app works in Smalltalk-80 and examine how it can be implemented in ActionScript. I am not a Smalltalk programmer and my first task was to find some good resources.
Trygve Reenskaug is credited with the first MVC formulation in Smalltalk in the late 70’s. However, the MVC metaphor was burned into Smalltalk and matured after Reenskaug left Xerox Parc. I found two useful resources on MVC in Smalltalk-80. The first is A cookbook for using the model-view controller user interface paradigm in Smalltalk-80 by Glenn Krasner and Stephen Pope. The second resource is Applications Programming in Smalltalk-80: How to use Model-View-Controller (MVC) by Steve Burbeck.
Although comprehensive, Krasner and Pope’s article is very readable from an ActionScript perspective. I could just about follow the Smalltalk code listings, identify the early OOP features and appreciate the ancestors of contemporary UI components. What stood out was how little things have changed in the last 20 to 30 years in OOP and GUI programming. I think the more appropriate observation is how advanced Smalltalk was for its time. Krasner and Pope’s essay is the primary resource for this post.
Model-View-Controller Implementation in Smalltalk-80
The MVC pattern facilitates the separation of concerns when developing interactive graphical applications. The logic and state of the application, how users interact with the application, and how application state is presented to the user are handled by separate elements of the MVC triad. Smalltalk-80 uses the MVC metaphor to provide built-in support for interactive application development. The idea was to provide a set of built-in user interface widgets such as buttons, menus and lists that can be plugged into a GUI application. To use these built-in UI widgets effectively, the application had to be built in accordance with the MVC metaphor. Let’s take a look at the conceptual diagram of a Smalltalk-80 MVC app.

Conceptual diagram of MVC in Smalltalk-80 (from Krasner & Pope)
All objects in Smalltalk communicate with each other via messages. Think of messages as a way to invoke methods in an object.
At first glance, the MVC conceptual diagram seemed a little strange. The multitude of arrows indicated more acquaintances than I’m used to seeing in an MVC diagram. Model-View and Controller-Model dependencies ran both ways. The second interesting aspect was that user input goes directly to the Controller. This is a significant change as we generally expect users to interact with UI widgets in the View. In Smalltalk-80, it looks like the raw keyboard and mouse input is fed directly to the Controller. Let’s take a quick look at how the MVC metaphor is supported in Smalltalk-80. Continue reading ‘Separated Presentation: The Classic Model-View-Controller Pattern’

Truckin' thru MVC
The MVC remains one of the most valuable structures for understanding and using Design Patterns, and yet I believe it to be misunderstood and misused on just about every level imaginable. In the first chapter of their book, the Gang of Four spend a mere two pages describing MVC in order to help readers understand the concept of a “pattern.” Unfortunately, the language used may have been the culprit leading to widespread uses for which the MVC was never intended. In introducing the MVC, GoF note,
Looking at the design patterns inside MVC should help you see what we mean by the term “pattern.”
The phrase, the design patterns inside MVC is where the trolly may have jumped the tracks.
Continue reading ‘Truckin’ Through ActionScript 3.0 MVC: Part V—Purpose and Use’

Truckin' thru MVC
I mentioned that updating and changing programs is the
sine qua non of Design Patterns. Further, I promised that it wouldn’t take very long to get to Part IV of this series because all I was going to do was to update the original compass program. So that’s what I did, and here is Part IV of
Truckin’ Through ActionScript 3.0 MVC.
Adding an Interface for the View
Before adding another view, I wanted to add an interface so that I could use the same Model and Controller classes. The changes are minimal in the revised View classes, and I changed the Client so that it could more easily request any view the user would like. Since you have all of the details about how the MVC works in Parts I-III, I’ll get right into the interface.
In looking at the View class in Part III, you can see that the class has only two methods. By putting them into an interface, we can program to the interface instead of the implementation. That means that as long as the same interface is used, you can use the same Model and Controller without any changes at all. As usual, interfaces are fairly short, and this one is no exception.
1
2
3
4
5
6
7
8
9
10
11
| package
{
import flash.display.Sprite;
import flash.events.Event;
public interface IView
{
function createView(vessel:Sprite):Sprite;
function update(e:Event):void;
}
} |
Before continuing, click the Play button to test both compasses that have their roots in that interface. (compi?)

The Model and Controller classes are identical for both compass examples. Read on to see how easy it is to add views.
Continue reading ‘Truckin’ Through ActionScript 3.0 MVC: Part IV—Making Changes’

Truckin' thru MVC
It’s been a busy month, and finishing up a simple MVC example took me longer than I expected. Chandima’s chapter (Chapter 12) lighted the way, and I also found valuable ActionScript 3.0 examples by
Bill Trikojus and Anthony Kolber . So if you experience a sense of
déjà vu, it’s from the MVC’s by Chandima, Bill and Anthony.
Taking Control
In Part II of this series on the MVC, we saw how we could separate the Model (data provider) from the View (a representation of the Model’s data—a graphic compass.) The process was simple enough, especially since all we needed from the Model was a value between 0 and 360. We made it even simpler by using constants with cardinal directions. In this final piece of the MVC puzzle, we’re adding a Controller class. The Gang of Four state that the
…Controller defines the way the user interface reacts to the user input
The UI for the controller is a Slider component set up with values ranging from 0 to 360. The View class instantiates the Sldier with Slider change events sent to the Controller class. In turn the Controller sends the Slider values to the Model, which updates its current value. The update is sent to the View class which rotates the compass needle.
Continue reading ‘Truckin’ Through ActionScript 3.0 MVC: Part III—An Analog Compass’

Truckin' thru MVC
I was going over Chapter 12 in our book that Chandima wrote on the MVC. It’s one of those chapters that has everything you need to get started on the MVC; so, I’ll use it as an anchor for my comments and make references to different parts of it to so as not to be redundant—in other words I won’t repeat what Chandima has so well and clearly stated. Instead, I want to focus on moving toward problem-solving using larger structures.
Straws and Stacks: MVC as a Reality sui generis
Years ago in an introductory sociology course, I became acquainted with the concept of a reality sui generis. Some of you may have come across the term elsewhere with different meanings in different contexts. Biology, law and political science have their contextual uses of the term, but the one we’re using here is the one from sociology. Emile Durkheim employed the term in his work, Suicide, to describe a social fact. For Durkheim, a social fact is a phenomenon of social behavior not reducible to its component parts. A bureaucracy is an organizational arrangement that we think of independent of those who actually make up the bureaucracy. It is a reality sui generis—a reality in and of itself. So, we can study phenomenon like families, groups, and organizations as being separate from the people who make them up. Each has characteristics that cannot be seen in the individuals.
To help us understand the concept, we were given the example of a stack and the individual straws that make up the stack. Straws and stacks have wholly different features even though one exists because of the other. By the same token, the MVC, while made up of objects, has characteristics independent of those objects. So, we might envision the MVC as a reality sui generis.
Continue reading ‘Truckin’ Through ActionScript 3.0 MVC: Part II—Reality Sui Generis or Collection of Spare Parts?’
Recent Comments