Predefined Classes Lesson 14 Contents

Mops comes with a large number of predefined classes that provide you with a strong foundation upon which to build your programs. The more you know about these classes, their methods and the functionality of the objects they create, the more comfortable you will be in designing your programs. Mops in many ways is like an Erector Set, it provide many pre-built pieces, you provide the imagination to turn those pieces into a usable program.

Predefined classes serve an important function in Mops. They insulate you from the concerns of extensive coding required for all the commonly used Mac functionality: windows, dialogs, menus, graphics, disk file manipulation, and dozens more. The nature of the methods in the predefined classes will be largely understandable to you by the time you're finished with this tutorial.

What this all means is that while you send comparatively simple messages to objects created from those classes, you are automatically performing very sophisticated operations not far different from those that an Assembly Language programmer would use. You are also left with fewer concerns about making your program Mac-like, since the predefined classes lead you in the right direction from the very start.
To a large extent the predefined classes act as the Macintosh development environment or framework that is provided with more traditional compiler languages. They are part and parcel of the Mops object orientation also.

You will soon want to begin scanning through the source code of the predefined classes. While much of the code is already compiled in the application files PowerMops and Mops.dic, all the Mops source code is supplied, in the folders "Mops source" and "Mops ƒ". You can view and print the source code files using any text editor. Eventually, you may find it helpful to print out some of the source code in the System, Toolbox, and Demo class folders within the Mops source folder. (Some of the Toolbox files refer to source code in the Modules folder.)

Mops predefined classes are divided into three groups. One group, called Mops System classes, consists of classes that are not necessarily specific to the Macintosh Toolbox. The System classes control things like file manipulation, basic data structures (integers, variables, arrays), and other computer housekeeping tasks. These classes of course have been designed to work specifically with the Macintosh, but they work largely behind the scenes, since they don't directly affect the way you and the computer communicate with each other.

A second group, called Toolbox classes, are those that make the connection between the programmer/user and the graphic elements of the Macintosh. "Graphic elements" is a broad category that includes such things as menus, windows, text input, mouse manipulation, and program control via the mouse or keyboard. The Toolbox classes are the highly visible, "show biz" classes of Mops.

The third group, Demo classes, consists of demonstration-program files, covered later in this tutorial.

Most of the predefined classes in both categories are subclasses of a kind of master Superclass, called class Object. While class Object, itself, is a subclass of yet another superclass, class Meta, you won't have to concern yourself with that particular relationship. Just think of class Object as the ultimate superclass of all classes, and you won't go wrong. Class Object is predefined in Mops, in the Mops source file "Class". It has very primitive functionality, and no instance variables.

Data structure classes
Among the most used predefined classes are several that are grouped into a cluster called "data structures." They provide the basic data structures as very basic objects. These classes form the basis of much number and string (text character) storage and manipulation in a Mops program.

In the rectangle example in Lesson 12 you already saw how instance variables of one basic data structure class, Int, were used as components of coordinate point objects, which were in turn used as components for a rectangle object.

The diagram below shows the organization of the Mops data structure classes, which are listed in the files called "Struct" and "Struct1".
The classes to the left of the vertical line are called scalar classes because they reserve a fixed amount of memory space for each instance of their class (just like a ruler marks a fixed area according to its "scale"). An integer object, for example, always has two bytes reserved for data (regardless of those bytes being meaningful data when an integer object is created).

DataStructure.png To the right of the vertical line in this diagram are a group of indexed classes. You can tell from the names of most of them that these classes provide the rules for setting up arrays in Mops programs. An indexed array is a convenience that helps your program reach into a list of data in memory and pick out desired pieces.

Consider that an array object might look something like this in memory:

IndexedData.png Notice that some data cells have reference numbers attached to them. Each number is an index (like an index tab in a three-ring binder) to that data cell. It is much easier and more efficient to reference an object's data by an index number than it is to provide the address in memory for the datum your program needs at a given moment.

The differences between the various indexed classes include the number of bytes each data cell is to contain (1, 2, or 4) and other considerations discussed later.

You'll also notice that the class Ordered-col has two lines leading to it. This is because it has two superclasses, that is, it uses multiple inheritance. The class (col) defines some methods that all "collection" type classes need, regardless of the size of their elements. Then the array superclass determines that the class Ordered-col has 4-byte elements.

The class (col) is an example of a class which doesn't have any objects of its own. It is just a convenient way of defining a group of classes, where these classes have a number of methods in common. Rather than repeat the definitions of these methods in each class definition, we "split them off" into a single superclass in which they can be defined just once.
We call this kind of superclass a generic superclass The class Longword is another example of a generic superclass. It is useful for defining methods common to the classes Var and Handle, but it doesn't have any objects of its own.

Other Predefined Classes
Another group of classes that gets a workout is the one that links you to QuickDraw, which is the classic Macintosh's powerful tool for accessing many of its graphics features.

This diagram shows the QuickDraw classes and the superclasses from which they were derived:

Other graphics oriented classes include those that help you create windows, menu bars, and menus, plus a class called Control that handles reactions to clicking the Mac mouse on buttons and scroll bars.

In addition, there are numerous predefined classes and objects that give you shortcuts to opening and closing files, sending output to the printer, producing sound, and other functions. Part III of this manual contains in depth explanations of all frequently used Mops classes. You will look to these reference sections very often once you have completed this tutorial.

Previous Chapter Contents Next Chapter
This page online:  http://PowerMops.com/MopsManual/Lessons/Chapter14.html