- 2.2.13.5. -
Table of Contents
2. TMT Pascal Language Description
2.2. Pascal Language Structure
2.2.13. OOP Extensions
2.2.13.5. OOP Scopes
2.2.13.5. OOP Scopes
Component identifiers are visible in all the methods throughout the domain
of the object, including the procedures, functions, destructors and
constructors that implement the methods of the object type and its descendants.
However, the scopes of the fields and methods declared in the private
section of the object type declaration are restricted to the unit that contains
the definition of the object type. private fields and methods are
inaccessible from other units. Private fields and methods can, however, be
accessed from other object types declared in the same unit. Below are examples
of several objects:
type
Point = record
X,Y: Longint;
end;
type
Circle = object
Center: Point;
Radius: Longist;
procedure Show;
procedure Hide;
end;
type
Ellipse = object (Circle)
Radius2: Longint;
Angle: Real;
procedure Show;
procedure Rotate(NewAngle: Real);
end;
Here, the object type Ellipse inherits the Center and
Radius fields from Circle. It also adds new Radius2
and Angle. Furthermore, it uses the method Hide inherited from
Circle; it overrides the method Show and adds a new method,
Rotate. The declaration of an object file includes just the headers
of the methods. The methods themselves should appear somewhere within the
current scope. In this way, method declarations are similar to forwarded
routines. When specified, methods names are qualified with object names.
For example
procedure Circle.Draw;
begin
Graph.Circle(X,Y,Radius);
end;
Note that within the method declaration, the fields of the object are visible
to the compiler.
- 2.2.13.5. -