caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jacques Garrigue <garrigue@kurims.kyoto-u.ac.jp>
To: Frederic.Tronel@inrialpes.fr
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] A question about classes and multiple inheritance
Date: Fri, 24 May 2002 09:29:45 +0900	[thread overview]
Message-ID: <20020524092945Y.garrigue@kurims.kyoto-u.ac.jp> (raw)
In-Reply-To: <3CECCCB3.72B4ED20@inrialpes.fr>

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


      reply	other threads:[~2002-05-24  0:30 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-05-23  8:51 Frederic Tronel
2002-05-23  9:52 ` Jacques Garrigue
2002-05-23 11:04   ` Frederic Tronel
2002-05-24  0:29     ` Jacques Garrigue [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20020524092945Y.garrigue@kurims.kyoto-u.ac.jp \
    --to=garrigue@kurims.kyoto-u.ac.jp \
    --cc=Frederic.Tronel@inrialpes.fr \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).