March 94 - USING PROTO TEMPLATES ON THE NEWTON
USING PROTO TEMPLATES ON THE NEWTON
HARRY R. CHESLEY
Proto templates are a central feature of the Newton development environment. All
Newton applications use built-in prototypes, and developers can also write their own
application-specific prototypes. This article uses proto templates in the design of an
application that plays a few simple games. For non-Newton developers it reveals some
of the flavor of designing and writing Newton applications.
An application often includes multiple instances of a design element, with only minor
variations among them. In object-oriented systems, it's possible to share the common
portions of the design among several different pieces of the application by using
inheritance. On the Newton, you can do this withproto templates , which let you reuse
the definition of a particular type of view very efficiently. Since views are the basic
visual and functional elements of the Newton user interface, proto templates give you a
very powerful ability to share and reuse user interface features.
Built-in proto templates supply most of the common views seen in Newton
applications -- push buttons, pop-up menus, checkboxes, radio buttons, and so on. In
addition, developers of Newton applications can define their own proto templates. These
templates allow for very compact designs, shorter development times, easier
maintenance, and smaller finished applications.
In this article we develop a game application for the Newton called TapBoard. TapBoard
is actually three games, each with its own style of board, rules of play, and algorithm
for computer-generated moves. The games have many elements in common, and these
can be abstracted into a proto template containing the shared aspects of the design.
You'll find much of the code for TapBoard in the article; the complete source code can
be found on this issue's CD.
If you've never written a Newton application, see "(Slightly) Inside Newton
Programming" for an introduction to the development process and some of the Newton
terminology that's used in this article.
(SLIGHTLY) INSIDE NEWTON PROGRAMMING
BY GREGG WILLIAMS
Programming the Newton is different -- and I mean that in a good sense. Once you
digest the Newton documentation, you can create a simple application and have it
running on a Newton in about 15 minutes. The Newton development process encourages
lots of quick code/compile/debug cycles -- good for those of us who need positive
reinforcement on a regular basis -- and the cycle is short enough that you don't notice
a delay.
OVERVIEW
Before I describe how a Newton program works, here's an overview of the development
process. To create a Newton application, all you need is the Newton Toolkit (available
from APDA), a serial cable, a 68030 Macintosh with 8 MB of memory and 32-bit
addressing, and a Newton. You create your program with the Toolkit, compile it, and
then download it to a Newton that's connected to your Macintosh through a serial port.
Your completed application appears in the Extras drawer, just like any other
third-party Newton application.
Using tools from a floating window called the layout palette , you draw the layout of
your application -- what its screens should look like -- in layout windows. Not only
can you reuse the dozens of user interface definitions that the Newton Toolkit supplies,
you can create your own custom proto templates (more on proto templates below).
Each layout or custom proto template is stored as a separate file; all of these files,
plus optional files that contain the Macintosh-style resources your program needs,
are grouped into what's called a project .
Once you've drawn all your views, you can open a browser window (familiar to users
of object-oriented languages like Smalltalk and LISP). In the browser window, you can
add and modify both code and data associated with the objects in your program. The code
you write is in a new language called NewtonScript , which is a simple but