Object-Oriented Extensions to Pascal: what changed
Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.
Title: Object-Oriented Extensions to Pascal
| Old | New | Line | |
|---|---|---|---|
| 1 | + | **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. | |
| 2 | + | ||
| 3 | + | ## Enhancements to Extended Pascal | |
| 4 | + | ||
| 5 | + | ### Normative enhancements | |
| 6 | + | ||
| 7 | + | #### Already supported features | |
| 8 | + | ||
| 9 | + | These features are already supported in Free Pascal 3.0 and earlier with the modes [[Mode ObjFPC|OBJFPC]] and [[Mode Delphi|DELPHI]]. | |
| 10 | + | ||
| 11 | + | - The keyword **class** | |
| 12 | + | - Ancestor class in parentheses | |
| 13 | + | - **Create** and **Destroy** are the names of the constructor and destructor | |
| 14 | + | - **inherited** can be use to call a method from an ancestor class | |
| 15 | + | - **override** overrides virtual methods in ancestor classes | |
| 16 | + | - **abstract** specifies abstract methods | |
| 17 | + | - The implicit parameter **Self** | |
| 18 | + | - Type coercion | |
| 19 | + | - The membership operator **is**. | |
| 20 | + | - The **with** statement can be used with classes. | |
| 21 | + | ||
| 22 | + | #### Root class | |
| 23 | + | ||
| 24 | + | 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. | |
| 25 | + | ||
| 26 | + | #### Virtual methods | |
| 27 | + | ||
| 28 | + | All methods are virtual in OOE and thus the **override** directive must be used when replacing or augmenting them in descendant classes. | |
| 29 | + | ||
| 30 | + | #### Multiple inheritance | |
| 31 | + | ||
| 32 | + | OOE supports multiple inheritance with a defined resolution mechanism. | |
| 33 | + | ||
| 34 | + | #### Class types | |
| 35 | + | ||
| 36 | + | ##### Concrete classes | |
| 37 | + | ||
| 38 | + | These are classes made with the keyword **class** (already supported). | |
| 39 | + | ||
| 40 | + | ##### Abstract classes | |
| 41 | + | ||
| 42 | + | 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. | |
| 43 | + | ||
| 44 | + | ##### Property classes | |
| 45 | + | ||
| 46 | + | 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**. | |
| 47 | + | ||
| 48 | + | ###### TextWritable | |
| 49 | + | ||
| 50 | + | OOE specifies a **TextWritable** property class with two methods: **WriteObj** and **ReadObj**, both taking a variable parameter of type **text**. | |
| 51 | + | ||
| 52 | + | #### Deferred classes | |
| 53 | + | ||
| 54 | + | Classes can be declared before they're defined via \[**abstract**\|**property**\] **class** **..** **end;**. | |
| 55 | + | ||
| 56 | + | #### Class views | |
| 57 | + | ||
| 58 | + | 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*). | |
| 59 | + | ||
| 60 | + | #### Null | |
| 61 | + | ||
| 62 | + | OOE specifies **Null** to be used with classes like **nil** is for pointers. | |
| 63 | + | ||
| 64 | + | #### Changes to modules | |
| 65 | + | ||
| 66 | + | 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. | |
| 67 | + | ||
| 68 | + | ### Non-normative enhancements | |
| 69 | + | ||
| 70 | + | #### Generic types | |
| 71 | + | ||
| 72 | + | 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. | |
| 73 | + | ||
| 74 | + | #### Exception handling | |
| 75 | + | ||
| 76 | + | This and the related procedure **Assert** are mentioned, but no mechanism for using them is defined. | |
| 77 | + | ||
| 78 | + | #### Procedural variables | |
| 79 | + | ||
| 80 | + | This is discussed and dismissed. Free Pascal of course already supports procedural variables. | |
| 81 | + | ||
| 82 | + | #### Default parameters | |
| 83 | + | ||
| 84 | + | The **value** keyword is extended to include default parameters. | |
| 85 | + | ||
| 86 | + | #### Set extensions | |
| 87 | + | ||
| 88 | + | **set of** *class* | |
| 89 | + | ||
| 90 | + | #### Overloading methods | |
| 91 | + | ||
| 92 | + | This would go naturally with the suggested module extensions. | |
| 93 | + | ||
| 94 | + | #### Persistent objects, object evolution, object roles | |
| 95 | + | ||
| 96 | + | These aren't included in the specification due to their dubious usefulness. | |
| 97 | + | ||
| 98 | + | #### Access abstraction | |
| 99 | + | ||
| 100 | + | A mechanism for this isn't specified. | |
| 101 | + | ||
| 102 | + | #### Operator overloading and definition | |
| 103 | + | ||
| 104 | + | 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. | |
| 105 | + | ||
| 106 | + | --- | |
| 107 | + | *From the Free Pascal wiki, page "Object-Oriented Extensions to Pascal", as it stood on 2024-02-28 after a change by Alextp, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).* | |
| 108 | + | Category: FPC | |
| 109 | + | Category: Proposals |
