home *** CD-ROM | disk | FTP | other *** search
- OBJECT TYPE COMPATIBILITY.
- ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
-
- Turbo Pascal's strict type compatibility rules are relaxed to some extent
- as a result of inheritance. In addition to everything else, a descendant
- type inherits type compatibility with all its ancestor types.
-
- This extended type compatibility takes three forms:
- between object instances
- between pointers to object instances
- between formal and actual parameters.
-
- Descendant types can be freely used in place of ancestor types, but not
- vice versa. Thus if a point is a descendant of a location and a circle
- is a descendant of a point, then the following assignments are legal:
-
- ALocation := APoint;
- APoint := ACircle;
- ALocation := ACircle; but the reverse is not legal.
-
- Descendant types contain everything that their ancestor types contain by
- virtue of inheritance. Therefore a descendant type is either exactly the
- same size or usually larger than its ancestors, but never smaller.
- Assigning an ancestor object to a descendant object could leave some of
- the descendant's fields undefined after the assignment, which is dangerous
- and therefore illegal.
-
- In the assignment statement, only the fields that the two types have in
- common are copied from the source to the destination, so the assignment
- ALocation := ACircle;
- only copies the X and Y fields which the two have in common.
-
- Similarly pointers to descendant can be assigned to pointers to ancestors.
-
- PLocation := PPoint;
- PPoint := PCircle;
- PLocation := PCircle; but not vice versa.
-
- A formal parameter of a given object type can take as an actual parameter
- an object of its own or any descendant type. Thus if a procedure requires
- a parameter of type point, the actual parameter could be of type point or
- type circle but not location.
-
- COMPAT.TXT
- 1.6.93
-