A class,
or class type, defines a structure consisting of fields, methods,
and properties. Instances of a class type are called objects. The
fields, methods, and properties of a class are called its components or members.
·A field is essentially a variable that is part of
an object. Like the fields of a record, a class’s fields represent data items
that exist in each instance of the class.
·A method is a procedure or function associated
with a class. Most methods operate on objects, that is, instances of a class.
Some methods (called class methods) operate on class types
themselves.
·A property is an interface to data associated with
an object (often stored in a field). Properties have access specifiers,
which determine how their data are read and modified. From other parts of a
program outside of the object itself’s property appears in most respects like a
field.
Objects
are dynamically allocated blocks of memory whose structure is determined by
their class type. Each object has a unique copy of every field defined in the
class, but all instances of a class share the same methods. Objects are created
and destroyed by special methods called constructors and destructors.
A variable of a class type is actually a pointer that references an object. Hence more than one variable can refer to the same object. Like other pointers, class-type variables can hold the value nil. But you don’t have to explicitly dereference a class-type variable to access the object it points to. For example, SomeObject.Size := 100 assigns the value 100 to the Size property of the object referenced by SomeObject; you would not write this as SomeObject^.Size := 100.
类(class)或类类型(class type)定义了由域(fields)、方法(methods)和属性(properties)组成的结构。类类型的势力叫做对象(objects)。类的域、方法和属性叫做类的部件(components)或成员(members)。
·域作为对象的一部分,实质上就是变量。和记录中的字段相似,类的域表示的是类的每个实例中存在的数据项。
·方法是与类相关的过程或函数。大多数方法作用于对象即类的实例。一些方法(叫做类方法,class methods)作用于类类型自身。
·属性是与对象相关的数据的接口(通常存储在域中)。属性具有访问说明符(access specifiers),访问说明符决定如何读取和修改属性的数据。在对象自身属性之外、程序的其他部分,属性的出现和域是相同的
对象被动态分配内存块,其结构取决于对象的类类型。每个对象对其类中定义的域有一份唯一的拷贝,但同一个类的所有实例共享相同的方法。对象的创建和销毁分别通过特殊的方法构造器(constructors)和析构器(destructors)。
类类型的变量实际上是引用对象的指针。因此可以有多于一个变量引用同一个对象。和其他指针一样,类类型变量可以保存空指针值nil。然而,为了访问类类型变量指向的对象,不必(严格来说是不允许)明确地对变量解除参照。例如,语句SomeObject.Size := 100把数值100赋给由SomeObject引用的对象的Size属性,而不能写成SomeObject^.Size := 100。