A property, like a field, defines
an attribute of an object. But while a field is merely a storage location whose
contents can be examined and changed, a property associates specific actions
with reading or modifying its data. Properties provide control over access to
an object’s attributes, and they allow attributes to be computed.
The declaration of a property
specifies a name and a type, and includes at least one access specifier. The
syntax of a property declaration is
property propertyName[indexes]:
type index integerConstant specifiers;
where
·propertyName is any valid identifier.
·[indexes] is optional and is a sequence of parameter
declarations separated by semicolons. Each parameter declaration has the form identifier1,
..., identifiern: type. For more information, see Array properties.
·type must be a predefined or previously
declared data type. That is, property declarations like property Num:
0..9 ... are invalid.
·the index integerConstant clause is optional. For more
information, see Index specifiers.
·specifiers is a sequence of read, write,
stored, default
(or nodefault), and implements
specifiers. Every property declaration must have at least one read or write
specifier.
Properties are defined by their access specifiers. Unlike fields, properties
cannot be passed as var parameters, nor can the @ operator be
applied to a property. The reason is that a property doesn’t necessarily exist
in memory. It could, for instance, have a read method that retrieves a
value from a database or generates a random value.
Property overrides and redeclarations
属性就象域,它定义了对象的表征性质。但是,一个域只不过是一个存储位置,该位置的内容可以被检查和改变。属性通常关联指定的动作,该动作读取或修改属性的数据。属性提供超越访问对象性质的控制,并且属性允许对象性质被计算。
属性声明指定了名称和类型,并且至少包括一个访问说明符。属性声明的语法是
property propertyName[indexes]:
type index integerConstant specifiers;
这里,
· propertyName是一个任意的有效标识符。
· [indexes] 是可选的、分号隔开的参数声明序列。每个参数声明具有形式identifier1, ..., identifiern: type。更多信息见数组属性。
· type必需是一个预定义或先前定义的数据类型。简言之,象 property Num: 0..9 ... 这样的属性声明是非法的。
· 索引子句integerConstant 是可选的。更多信息见索引说明符。
· specifiers 是一个read、write、stored、default(或nodefault)以及implements的说明符序列。每个属性声明必需并且至少有一个read或write说明符。
属性由其访问说明符定义。和域不同的是,属性不能作为var参数传递,也不能适用于地址运算符 @ 的操作数。这是因为属性不必在内存中存在。例如,一个属性具有的read方法从数据库中获取值或者产生一个随机数。