Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] Recovering masked methods
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: John Prevost <j.prevost@c...>
Subject: Re: [Caml-list] Recovering masked methods (with CamlP4?)
>>>>> "ab" == Alessandro Baretta <alex@baretta.com> writes:

    ab> In my code, class a = object method m = ... end Provides basic
    ab> functionality common to all my inheritance hiearchy. Class a
    ab> *also* defines the actual type of all my inheritance
    ab> hieararchy, so I do not use subtyping at all; I use type
    ab> *identity*. That's because I'm building a graph of objects of
    ab> different classes, so all the objects in the graph need to
    ab> have the same type. I only use inheritance because of code
    ab> sharing. Now, class b = object inherit a ... end performs
    ab> extensive personalizations to the functionality provided by
    ab> class a, while always retaining the functionality of the
    ab> parent, which is accessed by sending messages to
    ab> super_a. Class var_b needs most of the functionality provided
    ab> by b, with the sole exception of one method, which I call here
    ab> m, which needs to be identical to the one defined in the root
    ab> of the hierarchy.

Okay--let me rephrase what you just said to make sure I understand
correctly:

You have a class "a" which has a lot of common methods.

You have a class "b" which reuses and changes those.

You have a class "var_b" which is identical to "b" except that method
"m" is the same as "a".

If that is correct, I have no idea why you want to inherit the way
you've been talking about!  Why in heaven's name wouldn't you just
write:

class a =
  object
    method m = ...
    method m1 = ...
    method m2 = ...
    ...
  end

class var_b =
  object
    inherit a
    method m1 = ...
    method m2 = ...
    ...
  end

class b =
  object
    inherit b
    method m = ...
  end

You've simply got the wrong ordering in your inheritance.  There's
absolutely no need for more functionality to support accessing "older"
methods in this case.  (I'd argue there's no need in any case.)  And
again, even if method m had to be different in var_b, it would be
better to use an inherited class which has the features common to b
and var_b.  In this case, that class is identical to b.

John.

-------------------
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