[Next] [Previous] [Up] [Top]

2. Object System Enhancements

2.3. Deriving Built-in Types from Other Built-in Types

All CTypes contain a reference to a structure descriptor that describes the instances of the type. The description includes all attributes of the instance as well as the methods that are available. This allows the built-in object to fully describe itself with a single mechanism that treats attributes and methods equally. In the current Python implementation the only way to determine if a built-in object has a particular attribute is to attempt to set or get its value. Self describing objects can answer questions about attribute existence without having to attempt a set or get operation. This make it relatively easy to write generic routines for querying, printing, saving, restoring, and even browsing object hierarchies. Since it is possible to write generic methods for common operations, inheritance of behavior becomes much more useful and worthwhile to support.

CType objects encapsulate the idea of a super-type, where the super-type of an object indicates the type object from which behavior and attributes can be inherited. A mechanism is also provided that facilitates the initialization of sub-type objects from the values in the super-type.


Deriving Built-In Classes in Python - 22 DEC 94
[Next] [Previous] [Up] [Top]

Generated with CERN WebMaker