From: Frederic Tronel <Frederic.Tronel@inrialpes.fr>
To: caml-list@inria.fr
Subject: Re: [Caml-list] A question about classes and multiple inheritance
Date: Thu, 23 May 2002 13:04:19 +0200 [thread overview]
Message-ID: <3CECCCB3.72B4ED20@inrialpes.fr> (raw)
In-Reply-To: <20020523185248D.garrigue@kurims.kyoto-u.ac.jp>
> By definition super is statically resolved, and self is dynamically
> resolved. This is actually the point.
I understood this point by tracking the path of a call to preBehavior.
>In ocaml you don't get two
> independent hierarchies of methods with multiple inheritance: methods
> with same name are merged, taking implementation from last one.
> The only way to get dynamic resolution is to go through self ("this").
>
> But this seems to be what you are doing anyway, calling
> this#localPreBehaviour. So what's the point in calling
> super#preBehaviour? You certainly don't want to call yourself.
> There's certainly some way to do what you are trying to do, but we
> have to know what you want.
>
> If what you want is to call a localPreBehaviour for each superclass,
> then it's difficult, because there's no real support for mixins, and
> there's no keyword to say that a method should not appear in
> subclasses.
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.
But of course, I feel there is a problem in this (contrary to Java
where super is unique) since ocaml supports multiple inheritance and
the binding of superclasses is left to the programmer.
A default "super" bound to the first inherited class (for example),
dynamically resolved would help building nice applications of objects.
Other scheme are certainly possible, but may lead to code that is
difficult
to maintain and understand.
Anyway, for those who are interested, I have found the following way to
solve the
problem:
class virtual behaviorSpecElement =
object (this)
method virtual localPreBehavior : (string,string) Hashtbl.t ->
specBehavior
method virtual superPreBehavior : (string,string) Hashtbl.t stack ->
specBehavior
method virtual preBehavior : (string,string) Hashtbl.t stack ->
specBehavior
end
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.
Frederic.
-------------------
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
next prev parent reply other threads:[~2002-05-23 11:06 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 [this message]
2002-05-24 0:29 ` Jacques Garrigue
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=3CECCCB3.72B4ED20@inrialpes.fr \
--to=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