Warning: This is the manual of the legacy Guile 2.0 series. You may want to read the manual of the current stable series instead.

Next: , Previous: , Up: GOOPS   [Contents][Index]


8.7 Inheritance

Here are some class definitions to help illustrate inheritance:

(define-class A () a)
(define-class B () b)
(define-class C () c)
(define-class D (A B) d a)
(define-class E (A C) e c)
(define-class F (D E) f)

A, B, C have a null list of superclasses. In this case, the system will replace the null list by a list which only contains <object>, the root of all the classes defined by define-class. D, E, F use multiple inheritance: each class inherits from two previously defined classes. Those class definitions define a hierarchy which is shown in Figure 8.2. In this figure, the class <top> is also shown; this class is the superclass of all Scheme objects. In particular, <top> is the superclass of all standard Scheme types.

          <top>
          / \\\_____________________
         /   \\___________          \
        /     \           \          \
    <object>  <pair>  <procedure>  <number>
    /  |  \                           |
   /   |   \                          |
  A    B    C                      <complex>
  |\__/__   |                         |
   \ /   \ /                          |
    D     E                         <real>
     \   /                            |
       F                              |
                                   <integer>

Figure 8.2: A class hierarchy.

When a class has superclasses, its set of slots is calculated by taking the union of its own slots and those of all its superclasses. Thus each instance of D will have three slots, a, b and d). The slots of a class can be discovered using the class-slots primitive. For instance,

(class-slots A) ⇒ ((a))
(class-slots E) ⇒ ((a) (e) (c))
(class-slots F) ⇒ ((e) (c) (b) (d) (a) (f))

The ordering of the returned slots is not significant.


Next: , Previous: , Up: GOOPS   [Contents][Index]