objects with no ancestor are not implicitely final

This commit is contained in:
Araq 2012-08-24 17:33:04 +02:00
commit d17caa86e8
15 changed files with 44 additions and 22 deletions

View file

@ -970,9 +970,10 @@ in future versions of the compiler.
person = ("Peter", 30)
The implementation aligns the fields for best access performance. The alignment
is compatible with the way the C compiler does it. For consistency
with ``object`` declarations, tuples in a ``type`` section can also be defined
with indentation instead of ``[]``:
is compatible with the way the C compiler does it.
For consistency with ``object`` declarations, tuples in a ``type`` section
can also be defined with indentation instead of ``[]``:
.. code-block:: nimrod
@ -988,7 +989,7 @@ the ``of`` operator can be used to determine the object's type.
.. code-block:: nimrod
type
TPerson = object
TPerson {.inheritable.} = object
name*: string # the * means that `name` is accessible from other modules
age: int # no * means that the field is hidden
@ -1002,7 +1003,9 @@ the ``of`` operator can be used to determine the object's type.
Object fields that should be visible from outside the defining module, have to
be marked by ``*``. In contrast to tuples, different object types are
never *equivalent*.
never *equivalent*. Objects that have no ancestor are implicitely ``final``
and thus have no hidden type field. One can use the ``inheritable`` pragma to
introduce new object roots apart from ``system.TObject``.
Object variants

View file

@ -74,7 +74,11 @@ section.
Inheritance is done with the ``object of`` syntax. Multiple inheritance is
currently not supported. If an object type has no suitable ancestor, ``TObject``
can be used as its ancestor, but this is only a convention.
can be used as its ancestor, but this is only a convention. Objects that have
no ancestor are implicitely ``final``. You can use the ``inheritable`` pragma
to introduce new object roots apart from ``system.TObject``. (This is used
in the GTK wrapper for instance.)
**Note**: Composition (*has-a* relation) is often preferable to inheritance
(*is-a* relation) for simple code reuse. Since objects are value types in