7 Defining classes

The user defined class interface provides a natural way to define new XPCE classes. It is both used to create higher level libraries that have the same interface as the built-in XPCE classes as to define entire applications. Many of the library modules and XPCE/Prolog demo programs are implemented as user-defined classes. The PceDraw demo is an elaborate example defined entirely in user-defined classes.

A user defined class lives in XPCE, just as any other XPCE class. There is no difference. Both use dynamic resolution of messages to method objects and then execute the method object. Both use the same object-management and storage facilities.

XPCE/Prolog user-defined classes have their methods implemented in Prolog. This provides a neat and transparent interface between the two systems.8XPCE defines four implementation techniques for methods. C-function pointers are used for almost all the built-in behaviour. C++-function pointers are used when classes are defined in C++ (Wielemaker & Anjewierden, 1994) . Instances of c_pointer are left to the host object for interpretation and finally, code objects are executed.

User defined classes are defined using Prolog syntax, where some operators have special meaning. The definition of an XPCE/Prolog class is enclosed in

:- pce_begin_class(<Class>, <Super> [, <Comment>]).
<Class definition>
:- pce_end_class.

Multiple classes may be defined in the same Prolog source file, but class definitions may not be nested.

Section Index

7.1 The class definition skeleton
7.1.1 Definition of the template elements Syntax details
7.2 Accessing instance variables (slots)
7.3 Refining and redefining methods
7.3.1 General redefinitions
7.3.2 Redefinition in graphical classes
7.4 Handling default arguments
7.5 Advanced topics
7.5.1 More on type declarations
7.5.2 Methods with variable number of arguments Using class templates
7.5.3 Implementation notes