- 2.2.13.6 -
TMT Pascal Language Description
Pascal Language Structure
OOP ExtensionsPublic and Private declarations
Public and private are standard directives in the Object Pascal
language. Treat them as if they were reserved words. For readability, it is
best to organize an object declaration by visibility, placing all the
private members together, followed by all the protected
members, and so on. This way each visibility reserved word appears at most
once and marks the beginning of a new section of the declaration. So a typical
object declaration should look like this:
type
TObject = object
private
{ Private declarations}
public
{ Public declarations }
end;
The scope of component identifiers declared in private component
sections are restricted to the module that contains the object type
declaration. Keep in mind that:
- Inside the module, private component identifiers act like
normal public component identifiers.
- Outside the module, private component identifiers are unknown
and inaccessible.
Use the public part to
- Declare data fields you want methods in objects in other units to access
- Declare methods you want objects in other units to access
Declarations in the private part are restricted in their access.
If you declare fields or methods to be private, they are unknown
and inaccessible outside the unit the object is defined in.
Use the private part to
- Declare data fields you want only methods in the current unit to access
- Declare methods you want only objects defined in the current unit to
access
|
|
|
OOP Scopes |
Table of Content |
Virtual Methods |
- 2.2.13.6 -