Object-Oriented Extensions to Pascal

From Free Pascal wiki
Revision as of 23:09, 19 October 2017 by Keithbowes (talk | contribs) (Created a page about OOE, which I'd like to tackle after EP)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

Object Oriented Extensions to Pascal (abbreviated OOE) is an ANSI draft to extend Extended Pascal to support object-oriented programming. A Compiler Mode ooextpas is planned to cover this language mode (after Extended Pascal is implemented). It's similar to but different from the Object Pascal dialect of Free Pascal 3.0 and earlier.

Enhancements to Extended Pascal

Normative enhancements

Already supported features

These features are already supported in Free Pascal 3.0 and earlier with the modes OBJFPC and DELPHI.

  • The keyword class
  • Ancestor class in parentheses
  • Create and Destroy are the names of the constructor and destructor
  • inherited can be use to call a method from an ancestor class
  • override overrides virtual methods in ancestor classes
  • abstract specifies abstract methods
  • The implicit parameter Self
  • Type coercion
  • The membership operator is.
  • The with statement can be used with classes.

Root class

The class from which all other classes derive is called Root, instead of TObject. Root has two methods: Clone and Equal. Equal is equivalent to TObject's Equals. There's also a Copy function that does the same thing as the Clone method.

Virtual methods

All methods are virtual in OOE and thus the override directive must be used when replacing or augmenting them in descendant classes.

Multiple inheritance

OOE supports multiple inheritance with a defined resolution mechanism.

Class types

Concrete classes

These are classes made with the keyword class (already supported).

Abstract classes

These are classes made with abstract class. They're different from concrete classes in that they can't be constructed; instead, only a descendant class inheriting them can be constructed.

Property classes

These are classes that contain only the interface for its methods. The methods must be implemented in descendant classes. Property classes can only inherit from other property classes. They are declared via property class.

TextWritable

OOE specifies a TextWritable property class with two methods: WriteObj and ReadObj, both taking a variable parameter of type text.

Deferred classes

Classes can be declared before they're defined via [abstract|property] class .. end;.

Class views

Class views specify which methods can be visible to whom. It's used instead of the public, private, and protected sections of a class. They are declared via view of classname(inheritance-list).

Null

OOE specifies Null to be used with classes like nil is for pointers.

Changes to modules

Modules can export and rename classes and class members, make certain members protected, etc. It's expected that this expanded use of export will be generalized in future revisions of Extended Pascal. OOE also suggests that Extended Pascal be changed to allow parameter lists to be repeated in implementation modules so that function overloading will be possible.

Non-normative enhancements

Generic types

These weren't included in the normative specification because of their complexity, but their implementation is recommended. Generics in OOE are defined as being an application of schemata with the discriminant's type having the syntax type (type-list). These generic types would include generic classes.

Exception handling

This and the related procedure Assert are mentioned, but no mechanism for using them is defined.

Procedural variables

This is discussed and dismissed. Free Pascal of course already supports procedural variables.

Default parameters

The value keyword is extended to include default parameters.

Set extensions

set of class

Overloading methods

This would go naturally with the suggested module extensions.

Persistent objects, object evolution, object roles

These aren't included in the specification due to their dubious usefulness.

Access abstraction

A mechanism for this isn't specified.

Operator overloading and definition

Overloading existing operators or creating new ones is deemed useful, but there's no specified mechanism. Free Pascal supports PXSC-style operator overloading, but not operator definition. GNU Pascal permits defining new operators through operator overloading.