Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] A question about classes and multiple inheritance
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Jacques Garrigue <garrigue@k...>
Subject: Re: [Caml-list] A question about classes and multiple inheritance
From: Frederic Tronel <Frederic.Tronel@inrialpes.fr>

> Each subclass override the definition of localPreBehavior, and I want
> preBehavior to call first this#localPreBehavior, and then in turn 
> preBehavior method of its upper class (single inheritance),
> until it reaches the top level in the hierarchy. 
> This is the way it's done in Java for example.
> For this to be simple, I need "super" to be resolved dynamically.

I think you're confused. "super" is certainly resolved statically in
Java too: try to use super.preBehaviour when your parent class doesn't
define preBehaviour. Except maybe smalltalk, I believe super always
refer to the parent class of the class in which you are defining yur
method.

abstract class A {
    abstract void m();
}

class B extends A {
    void m () {
        super.m();
    }
}

Test.java:7: abstract method m() cannot be accessed directly
        super.m();
             ^
The problem only appears if you are using mixins, but Java has no
mixins, and ocaml multiple inheritance does not really support them
either.

Remark also that in many cases use of higher-order functions and lists
of function can provide a very clean non-oo solution to this kind of
problem.


> and  virtual ['a] specElement =
>   fun (synchroAccounting : 'a) ->
>   object (this)
>   method superPreBehavior bindings = Null (* dummy definition *)
>   method preBehavior bindings =
>       let binding = bindings#top in
>       let myPre = this#localPreBehavior binding in
>       bindings#popSP ;
>       let superPre = this#superPreBehavior bindings in
>       bindings#pushSP ;
>      ....
> end
> 
> For each subclasses of specElement I define:
> 
> method superPreBehavior = super#preBehavior
> 
> It reduces the code duplication to this single definition. 

I don't understand what you are trying to do.
Since superPreBehaviour is not hidden, this will only recurse once:
you might call super#preBehaviour through superPreBehaviour, but in
the superclass you will be calling the same superPreBehaviour, not
super#super#preBehaviour as you seem to be expecting.

  Jacques
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners