t3x.org / t3x / t3x-manual / 296.html
 
T3X - A Minimum Procedural Language
Version 8.1.5, Online Edition
Copyright(C) 1996-2004
Nils M Holm
 
Previous:
2.9.5 Methods and Messages
TOC | Index | Back Next:
2.10 Interface Classes

2.9.6 Class Constants

Constants may be public as well:

PUBLIC CONST symbol = constant_expression;

Such constants can be accessed from outside the class by sending a special form of a message to the class which defines the constant. Given the constant MAXLEN of the class STRING:

PUBLIC CLASS string()
 PUBLIC CONST MAXLEN = 32767;
END

the expression

STRING.MAXLEN

is used to access the value of MAXLEN. So the general form of class constant access is

classname.constname

The 'classic' way of exporting such a constant would be to define a method returning the constant:

PUBLIC maxlen() RETURN 32767;

Class constants have the advantage of saving a procedure call. Since their values are known at compile time, they can also be used in constant expression contexts.

Structures can be exported in the same way as constants:

PUBLIC STRUCT structname = member1, ..., memberN;

Public structures are useful for describing structured arguments or return values of methods. For example, the SYSTEM.STAT function (the function STAT of the SYSTEM class) returns a structure containing information about a specific file. In addition, the SYSTEM class provides a public structure describing the layout of the structure delivered by the STAT function. This structure allows programs using the SYSTEM.STAT function to decompose the returned information.

Since class constants cannot be altered, they do not weaken the strict encapsulation principle. Public structures are an interface and an implementation at the same time.

Previous:
2.9.5 Methods and Messages
TOC | Index | Back Next:
2.10 Interface Classes